How to check if a string contains another string in JavaScript?

To check if a string contains another string in JavaScript you can use the indexOf function

Sample JS

var sampleString = "This is a String";
if(s.indexOf("is") > -1){
//do something
}

for more informations see w3schools JavaScript String indexOf() Method

Please Share us:
Please rate this snippet

One thought on “How to check if a string contains another string in JavaScript?

Leave a Reply