Javascript String includes()

The includes() method checks if one string can be found inside another string.

Example


includes() Syntax

The syntax of the includes() method is:

str.includes(searchString, position)

Here, str is a string.


includes() Parameters

The includes() method takes in:

  • searchString - A string to be searched for within str.
  • position (optional) - The position within str to begin searching for searchString. By default, it is 0.

includes() Return Value

  • Returns true if searchString is found anywhere within str.
  • Returns false if searchString is not found anywhere within str.

Note: The includes() method is case sensitive.


Example: Using includes() method

Output

true
false
false
false
true

Recommended Reading: JavaScript String indexOf()