search

String.prototype.includes

Returns true if searchString appears anywhere in the string, otherwise false. Added in ES2015 as a cleaner boolean alternative to indexOf() !== -1.

str.includes(searchString[, position])

Parameters

Parameter Purpose
searchString String to search for
position Index at which to begin searching (default 0)

Examples

console.log('hello world'.includes('world'));

Prints true

console.log('hello world'.includes('World'));

Prints false (case-sensitive)

console.log('hello'.includes('ell', 2));

Prints false (starts search at index 2)

console.log('abc'.includes(''));

Prints true (empty string always matches)

Gotcha

Does not accept a RegExp — passing one throws a TypeError. Case-sensitive; lowercase both sides for case-insensitive checks.

Related methods

← All JS string methods · JS array methods