String.prototype.includes()

The includes() method performs a case-sensitive search to determine whether one string may be found within another string, returning true or false as appropriate.

Try it

Syntax

includes(searchString)
includes(searchString, position)

Parameters

searchString

A string to be searched for within str.

position Optional

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.

Description

This method lets you determine whether or not a string includes another string.

Case-sensitivity

The includes() method is case sensitive. For example, the following expression returns false:

'Blue Whale'.includes('blue')  // returns false

You can work around this constraint by transforming both the original string and the search string to all lowercase:

'Blue Whale'.toLowerCase().includes('blue')  // returns true

Examples

Using includes()

const str = 'To be, or not to be, that is the question.'

console.log(str.includes('To be'))        // true
console.log(str.includes('question'))     // true
console.log(str.includes('nonexistent'))  // false
console.log(str.includes('To be', 1))     // false
console.log(str.includes('TO BE'))        // false
console.log(str.includes(''))             // true

Specifications

Specification
ECMAScript Language Specification
# sec-string.prototype.includes

Browser compatibility

BCD tables only load in the browser

See also