String.prototype.includes()

Determines whether a string contains the given substring.

Since ES2015 Spec ↗

Syntax

str.includes(searchString, position)

Parameters

NameTypeRequiredDescription
searchString string Yes The substring to search for.
position number No Position within the string to begin searching. Defaults to 0.

Returns

boolean — true if the substring is found; otherwise false.

Examples

console.log('hello world'.includes('world'));
Output
true
console.log('hello'.includes('H'));
Output
false

Notes

Case-sensitive. Cannot be used with a regular expression (throws TypeError if given one). Returns true when searching for an empty string.

Browser & runtime support

EnvironmentSince version
chrome 41
firefox 40
safari 9
edge 12
node 4.0

See also