La chaîne JavaScript contient
var string = "foo",
substring = "oo";
console.log(string.includes(substring));
Cautious Crane
var string = "foo",
substring = "oo";
console.log(string.includes(substring));
var colors = ["red", "blue", "green"];
var hasRed = colors.includes("red"); //true
var hasYellow = colors.includes("yellow"); //false
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)
const array1 = [1, 2, 3];
console.log(array1.includes(2));
// expected output: true
const pets = ['cat', 'dog', 'bat'];
console.log(pets.includes('cat'));
// expected output: true
console.log(pets.includes('at'));
// expected output: false
const pets = ['cat', 'dog', 'bat'];
console.log(pets.includes('cat'));
// output: true
includes(searchElement)
includes(searchElement, fromIndex)