xxxxxxxxxx
const string = "Hello, world!";
const substring = "world";
if (string.includes(substring)) {
console.log("Substring found");
} else {
console.log("Substring not found");
}
xxxxxxxxxx
var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
alert("Not again");
}
//use indexOf (it returns position of substring or -1 if not found)
xxxxxxxxxx
// Here's what the syntax looks like:
// string.includes(substring, fromIndex)
// Here's an example:
const bio = "I am a web developer";
console.log(bio.includes("web"));
// true
xxxxxxxxxx
let String = "codegrepper";
let Sub = "grepper";
console.log(String.includes(Sub)); // true