JavaScript Array includes() method determines whether an array contains a specific value or not. It returns a boolean value (true
or false
) based on whether the specified value exists in the array.

Pre-requisites to Learn
Syntax
arr.includes(valueToFind, fromIndex);
Parameters
Parameter | Description |
---|---|
valueToFind (Required) | The value to search for in the array. |
fromIndex (Optional) | The index to start the search from. Defaults to 0 . If negative, it counts from the end of the array. |
Return Value
The includes() method returns true
if the specified value is found in the array, otherwise returns false
.
Notes:
- The search is case-sensitive for strings.
- Unlike
indexOf()
, theincludes()
method can correctly detectNaN
as a valid value in the array. - It does not modify the original array.
Examples of JavaScript Array includes() Method
Example 1: Checking whether specific fruits are present in the array.
let fruits = ['apple', 'banana', 'cherry']; console.log(fruits.includes('banana')); // Output: true console.log(fruits.includes('grape')); // Output: false
Example 2: The includes() method is case-sensitive i.e. the 'apple'
and 'Apple'
are treated as different values.
let fruits = ['Apple', 'Banana', 'Cherry']; console.log(fruits.includes('apple')); // Output: false console.log(fruits.includes('Apple')); // Output: true
Example 3: The fromIndex
parameter specifies where the search should start. Negative values count backward from the end of the array.
let numbers = [10, 20, 30, 40, 50]; console.log(numbers.includes(30, 2)); // Output: true console.log(numbers.includes(30, 3)); // Output: false console.log(numbers.includes(30, -3)); // Output: true
Example 4: Handling NaN
Values – Unlike indexOf()
, which cannot detect NaN
, the includes()
method correctly identifies its presence.
let values = [1, 2, NaN, 4]; console.log(values.includes(NaN)); // Output: true
Example 5: In sparse arrays, empty slots are treated as undefined
by the includes()
method.
let sparseArray = [1, , 3]; console.log(sparseArray.includes(undefined)); // Output: true
Supported Browsers
Browser | Support |
---|---|
Chrome | 47+ |
Firefox | 43+ |
Safari | 9+ |
Edge | 14+ |
Opera | 34+ |
Internet Explorer | Not supported |
Comparison with Other Methods
Method | Purpose |
---|---|
Array.includes() Method | Checks if an array contains a value and handles NaN correctly. Returns true or false . |
Array.indexOf() Method | Returns the index of a value in an array or -1 if not found. Does not handle NaN . |
Array.some() Method | Checks if at least one element satisfies a given condition. |