String contains another string


Question

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

Regards

1
124
10/2/2018 2:09:57 PM

Accepted Answer

You can use .indexOf():

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

}
193
5/24/2011 10:10:42 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon