Elias
0
Q:

check if string contains character javascript

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)
17
"FooBar".includes("oo"); // true

"FooBar".includes("foo"); // false

"FooBar".includes("oo", 2); // false
4

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

var n = str.includes("world", 12);
 
0
var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
	alert("Not again");
}
6
if (your_string.indexOf('hello') > -1)
{
  alert("hello found inside your_string");
}
1

New to Communities?

Join the community