147

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

Regards

cнŝdk
  • 30,215
  • 7
  • 54
  • 72
donald
  • 23,289
  • 41
  • 138
  • 221

1 Answers1

214

You can use .indexOf():

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

}
Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111