String javascript contém
var string = "foo",
substring = "oo";
console.log(string.includes(substring));
Cautious Crane
var string = "foo",
substring = "oo";
console.log(string.includes(substring));
// use the variable.includes()
const myString = "hello world!"
if(myString.includes("hello")){
// do something
}else{
//also do something
}
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)
var email = "[email protected]";
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
"FooBar".includes("oo"); // true
"FooBar".includes("foo"); // false
"FooBar".includes("oo", 2); // false
if (your_string.indexOf('hello') > -1)
{
alert("hello found inside your_string");
}