Easy Tutorial
❮ Jsref Length Array Prop Checkbox Checked ❯

JavaScript Array includes() Method

JavaScript Array Object

Example

Check if the array site contains 'tutorialpro':

let site = ['tutorialpro', 'google', 'taobao'];

site.includes('tutorialpro'); 
// true

site.includes('baidu'); 
// false

Definition and Usage

The includes() method is used to determine whether an array contains a specified value among its entries, returning true if it does, and false otherwise.

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true
[1, 2, NaN].includes(NaN); // true

Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method Chrome Edge Firefox Safari Opera
includes() 47 14 43 9 34

Syntax

arr.includes(searchElement)
arr.includes(searchElement, fromIndex)

Parameter Values

Parameter Description
searchElement Required. The value to search for.
fromIndex Optional. The position in this array at which to begin searching for searchElement. If negative, it is taken as the offset from the end of the array. Default is 0.

Technical Details

Return Value: Boolean. Returns true if the specified value is found, otherwise returns false.
JavaScript Version: ECMAScript 6
--- ---

More Examples

fromIndex Greater Than or Equal to Array Length

If fromIndex is greater than or equal to the array length, false is returned. The array will not be searched.

Example

var arr = ['a', 'b', 'c'];

arr.includes('c', 3);   // false
arr.includes('c', 100); // false

Computed Index Less Than 0

If fromIndex is negative, the computed index is calculated as the starting position to search for the searchElement. If the computed index is less than 0, the entire array is searched.

Example

// Array length is 3
// fromIndex is -100
// Computed index is 3 + (-100) = -97

var arr = ['a', 'b', 'c'];

arr.includes('a', -100); // true
arr.includes('b', -100); // true
arr.includes('c', -100); // true

JavaScript Array Object

❮ Jsref Length Array Prop Checkbox Checked ❯