149

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

Regards

cнŝdk
  • 31,391
  • 7
  • 56
  • 78
donald
  • 23,587
  • 42
  • 142
  • 223

1 Answers1

214

You can use .indexOf():

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

}
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143