String contains another string

donald picture donald · May 24, 2011 · Viewed 169.7k times · Source

How can I check if a string contains another string instead of using "==" to compare the whole string?

Regards

Answer

Felix Kling picture Felix Kling · May 24, 2011

You can use .indexOf():

if(str.indexOf(substr) > -1) {

}