1const string = "javascript";
2const substring = "script";
3
4console.log(string.includes(substring)); //true
1var string = "foo";
2var substring = "oo";
3
4console.log(string.indexOf(substring) !== -1);
1let example = "Example String!";
2let ourSubstring = "Example";
3
4if (example.indexOf(ourSubstring) != 0) {
5 console.log("The word Example is in the string.");
6} else {
7 console.log("The word Example is not in the string.");
8}
1let example = "Example String!";
2let ourSubstring = "Example";
3
4if (str.includes(ourSubstring, 7)) {
5 console.log("The word Example is in the string.");
6} else {
7 console.log("The word Example is not in the string");
8}