How to Check Whether a String Contains a Substring in JavaScript?

How to check whether a string contains a substring in JavaScript?

You can also use the indexOf() method which returns the index of the first occurrence of the substring in the string, or -1 if the substring is not found. Here’s an example:

Or use search method that returns the index of the first match or -1 if not found

Both includes() and indexOf() methods are case sensitive and both are work fine on String objects.

Leave a Comment

Home
Menu
Instagram
Search