+ 1

Contains in javascript

does "contains" condition exsist in javascript? or else how can i do it?

13th Apr 2017, 8:59 PM
Stefano Trinca
Stefano Trinca - avatar
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.
13th Apr 2017, 11:22 PM
Rrestoring faith
Rrestoring faith - avatar
+ 6
Yes, includes() is the same as contains.
13th Apr 2017, 11:18 PM
Rrestoring faith
Rrestoring faith - avatar
+ 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;
13th Apr 2017, 9:03 PM
Nifriz
Nifriz - avatar
+ 1
how can i use includes()?
13th Apr 2017, 11:19 PM
Stefano Trinca
Stefano Trinca - avatar