JavaScript String.prototype.includes() Method
The includes() method checks whether a string contains another string, returning true or false. The search is case-sensitive.
Description
The includes() method of String values performs a case-sensitive search to find out whether one string appears inside another, and returns true or false. It reads more clearly than the older indexOf(text) !== -1 check.
The search is case-sensitive, so convert both strings with toLowerCase() for a case-insensitive check. To search with a pattern, use RegExp.prototype.test() instead; passing a regular expression to includes() throws a TypeError. Arrays have their own Array.prototype.includes() method, which checks for an element rather than text.
The optional second argument sets the position to start searching from, which lets you check part of a string without slicing it first. An empty search string always returns true, because every string contains the empty string. For a case-insensitive check across languages, compare lower-cased versions of both strings, or use localeCompare() with sensitivity: 'base' for whole-string comparisons.
Syntax
string.includes(searchString)
string.includes(searchString, position)Parameters
- searchStringThe text to search for. A regular expression is not allowed.
- positionOptional. The index to start searching from. Defaults to 0.
Return Value
true if the search string is found anywhere in the string, otherwise false.
Exceptions
- TypeErrorThrown if
searchStringis a regular expression.
Example
Browser Support
The following information will show you the current browser support for the String.prototype.includes() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





