Array.prototype.includes
Determines whether an array includes a certain value among its entries, returning true or false
Syntax
array.includes(searchElement, fromIndex?)Parameters
| Parameter | Type | Description |
|---|---|---|
| searchElement | T | The value to search for |
| fromIndex | number | Zero-based index at which to start searching |
Return Value
true if the value is found, false otherwise
Examples
const fruits = ['apple', 'banana', 'cherry'];
console.log(fruits.includes('banana')); // true
console.log(fruits.includes('grape')); // falseconst numbers = [1, 2, 3, NaN];
console.log(numbers.includes(NaN)); // trueconst arr = [1, 2, 3, 4, 5];
console.log(arr.includes(3, 3)); // false (starts at index 3)Understanding Array.prototype.includes
The Array.prototype.includes method in JavaScript determines whether an array includes a certain value among its entries, returning true or false. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.
The method signature is array.includes(searchElement, fromIndex?). It accepts 2 parameters: searchElement, fromIndex. When called, it returns true if the value is found, false otherwise. Understanding when and how to use includes() helps you write more expressive, readable code.
Common use cases for Array.prototype.includes include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-indexof, array-find, array-some, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Array.prototype.includes is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Array.prototype.indexOfReturns the first index at which a given element can be found in the array, or -1 if it is not present
Array.prototype.findReturns the first element in the provided array that satisfies the provided testing function
Array.prototype.someTests whether at least one element in the array passes the test implemented by the provided function
String.prototype.includesDetermines whether one string may be found within another string, returning true or false
More Array Methods
Other methods in the Array object
Related Tools
More Array Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.