Javascript – Check string contains

We can use the indexOf() function to check if a string exists in another string.

var s = "foo";
alert(s.indexOf("oo") != -1);

 

it returns true if s contains “oo” and vice versa.

Done =)

Reference: StackOverflow – javascript : string contains …

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.