Usually I would expect a String.contains()
method, but there doesn't seem to be one.
What is a reasonable way to check for this?
javascriptstringstring-matchingsubstring
Usually I would expect a String.contains()
method, but there doesn't seem to be one.
What is a reasonable way to check for this?
Best Solution
ECMAScript 6 introduced
String.prototype.includes
:includes
doesn’t have Internet Explorer support, though. In ECMAScript 5 or older environments, useString.prototype.indexOf
, which returns -1 when a substring cannot be found: