JavaScript Array includes() Method
Example
Check if an array includes "Mango":
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
Try it Yourself »
Definition and Usage
The includes() method determines whether an array contains a specified element.
This method returns true if the array contains the element, and false if not.
Note: The includes() method is case sensitive.
Browser Support
Method | |||||
---|---|---|---|---|---|
includes() | 47 | 14.0 | 43 | 9 | 34 |
Syntax
array.includes(element, start)
Parameter Values
Parameter | Description |
---|---|
element | Required. The element to search for |
start | Optional. Default 0. At which position in the array to start the search |
Technical Details
Return Value: | A Boolean |
---|---|
JavaScript Version: | ECMAScript 7 |
More Examples
Check if an array includes "Banana", starting the search at position 3:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Banana", 3);
Try it Yourself »
Related Pages
JavaScript Tutorial: JavaScript Arrays
❮ JavaScript Array Reference