JavaScript Array.prototype.includes() Method
The includes() method checks whether an array contains a certain value, returning true or false.
Description
The includes() method determines whether an array contains a value, returning true or false. It compares using SameValueZero, which is like === except that NaN is found too (indexOf() can't find NaN).
Objects are only found if it's the same object, not one with the same contents; use some() or find() to match by property. For repeated lookups in a large collection, a Set is faster.
A second argument sets where to start searching, and negative values count from the end, so arr.includes(x, -3) only checks the last three elements. Empty slots in sparse arrays are treated as undefined, so [ , 1].includes(undefined) is true. Strings have their own includes() method for finding text within a string.
Syntax
array.includes(searchElement)
array.includes(searchElement, fromIndex)Parameters
- searchElementThe value to look for.
- fromIndexOptional. The index to start searching from. Negative values count from the end.
Return Value
true if the value is found, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.includes() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





