Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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));

image

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...