javascript string contains function
snippet in javascript

javascript string contains

user1420

var string = "foo",
    substring = "oo";

console.log(string.includes(substring));

javascript string contains function

user9948

s = "Hello world";
console.log(s.includes("world"));

javascript contains substring

user5449

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)

javascript includes

user6787

const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// output: true

javascript if contains character

user5310


var str = "Hello world, welcome to the universe.";

var n = str.includes("world", 12);