Array

Array.prototype.includes

Determines whether an array includes a certain value among its entries, returning true or false

Syntax

JavaScript
array.includes(searchElement, fromIndex?)

Parameters

ParameterTypeDescription
searchElementTThe value to search for
fromIndexnumberZero-based index at which to start searching

Return Value

true if the value is found, false otherwise

Examples

Basic Usage
const fruits = ['apple', 'banana', 'cherry'];
console.log(fruits.includes('banana')); // true
console.log(fruits.includes('grape')); // false
Practical Example
const numbers = [1, 2, 3, NaN];
console.log(numbers.includes(NaN)); // true
Advanced Usage
const 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

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.