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?
ECMAScript 6 introduced href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes"
rel="noreferrer">String.prototype.includes
:
class="snippet" data-lang="js" data-hide="false" data-console="true"
data-babel="false">
class="snippet-code-js lang-js prettyprint-override">
var string =
"foo",
substring =
"oo";
console.log(string.includes(substring));
No comments:
Post a Comment