1const string = "javascript";
2const substring = "script";
3
4console.log(string.includes(substring)); //true
1var str = "We got a poop cleanup on isle 4.";
2if(str.indexOf("poop") !== -1){
3 alert("Not again");
4}
5//use indexOf (it returns position of substring or -1 if not found)
1const pets = ['cat', 'dog', 'bat'];
2
3console.log(pets.includes('cat'));
4// output: true
1
2var str = "Hello world, welcome to the universe.";
3var n = str.includes("world");
4
1
2var str = "Hello world, welcome to the universe.";
3
4var n = str.startsWith("Hello");
5
1var str = "We got a poop cleanup on isle 4.";
2if(str.indexOf("poop") !== -1){
3 alert("Not again");
4}