gramm gramm - 2 months ago 9x
Javascript Question

How to check if one string contains another substring in Javascript?

Usually, I would expect a

method, but there doesn't seem to be one. What is a reasonable way to check for this?


String.prototype.indexOf returns the position of the string in the other string. If not found, it will return -1:

var string = "foo",
    substring = "oo";
console.log(string.indexOf(substring) !== -1);