Array includes()
The includes() method of arrays and typed arrays returns whether a given value appears in the array.
Overview
The includes() method of arrays and typed arrays returns whether a given value appears in the array.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 47 | 14 | 43 | 9 | 47 | 9 | |
| Built-in object | ||||||
| The includes() method of TypedArray instances determines whether a typed array includes a certain value among its entries, returning true or false as appropriate. This method has the same algorithm as Array.prototype.includes(). | 47 | 14 | 43 | 10 | 47 | 10 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
const fruits = ['apple', 'banana', 'cherry'];
fruits.includes('banana'); // true
fruits.includes('grape'); // false
// Checking for NaN (impossible with indexOf)
[1, 2, NaN].includes(NaN); // true
[1, 2, NaN].indexOf(NaN); // -1 Live demo
Use cases
Using Array includes()
The includes() method of arrays and typed arrays returns whether a given value appears in the array.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.
Related links
Powered by web-features