Home >>JavaScript Array Reference >JavaScript Array includes() Method
The JavaScript array includes() method is an inbuilt function in JavaScript which is used to check whether the given array contains the specified element, it returns true or false as appropriate. It returns true if the element is present in an array, otherwise false.
Syntax:array.includes(searchElement)
Parameter | Description |
---|---|
element | It is required. The element which is searched |
start | It is optional. It represents the element at which position in the array to start the search. Default is 0. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
includes() | 47 | 14.0 | 43 | 9 | 34 |
<html> <body> <p id="arrinc"></p> <script> var color = ["Red", "Blue", "Green", "Yellow"]; var x = color.includes("Yellow"); document.getElementById("arrinc").innerHTML = x; </script> </body> </html>
<html> <body> <script> var inc1=["HTML","CSS","BOOTSTRAP"] var res=inc1.includes("AngularJS",1); document.writeln(res); </script> </body> </html>