Back
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?
There are many ways to check whether a string contains a substring in JavaScript some of them I am mentioning here:-
The ES6 introduced a method String.includes()this method will return true or false depending upon the result:
var string = "xyzb", substring = "yz"; console.log(string.includes(substring));
31k questions
32.8k answers
501 comments
693 users