строка содержит в JavaScript
const string = "foo";
const substring = "oo";
console.log(string.includes(substring));
2 Programmers 1 Bug
const string = "foo";
const substring = "oo";
console.log(string.includes(substring));
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 pets = ['cat', 'dog', 'bat'];
console.log(pets.includes('cat'));
// output: true
var email = "grepper@gmail.com";
if(email.includes("@")){
console.log("Email is valid");
}
else{
console.log("Email is not valid");
}
// includes return boolean, if your string found => true else => false
bigstring.includes("string") // return true or false
if (your_string.indexOf('hello') > -1)
{
alert("hello found inside your_string");
}