+ 1
Contains in javascript
does "contains" condition exsist in javascript? or else how can i do it?
4 Answers
+ 5
@Steano
It returns true if the string contains the sequence of chars, same as contains.
var str = "chars";
if(str.includes("ch"))
// has ch
You don't have to use an if, but thats one way of doing it. You could also do what @Daniele said, it's equavalent.
+ 6
Yes, includes() is the same as contains.
+ 2
The indexOf function is used for finding the occurance of a string within a string and returning the index of that string. example
r.indexOf(s) !== -1;
+ 1
how can i use includes()?