0 votes
1 view
in Web Technology by (47.8k points)

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?

1 Answer

0 votes
by (107k points)

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));

image

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...