How to check if the String contains the Substring in Javascript?

String Includes method in Javascript

Includes( ) is one of the String method in Javascript. It is used to checks whether a string contains the specified string/characters and returns true or false based on matching.

Syntax of includes method in Js

  • searchString – A string to be searched for within str.
  • position – The position within the string at which to begin searching for searchString. (Defaults to 0.)
  • Return value – true if the search string is found anywhere within the given string; otherwise, false if not.

Example for Includes method

As mentioned in code, the input String value is “revisit class” and the substring value that we want to search is “revisit”. To check whether the string contains the substring or not, we have used includes method like “inputString.includes(subString)“.

This method will return the true if the Input string contains the sub string value. Otherwise it will return false.

Output:

Use case : Check the email service provider using includes method

Output

Recommended Articles