Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (47.6k 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 (106k 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));


Related questions

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

30.5k questions

32.5k answers


108k users

Browse Categories