JavaScript | array.includes() function
The array.includes() is an inbuilt function in JavaScript which is used to know either a particular element is present in the array or not and accordingly, it returns true or false i.e, if the element is present, then it returns true otherwise false
Syntax:
array.includes(searchElement)
Parameter:
searchElement: It is the element which is searched.
Return Value:
It return a Boolean value i.e, either True or False.
Examples:
Input: [1, 2, 3, 4, 5].includes(2); Output: true Input: [1, 2, 3, 4, 5].includes(9); Output: false
JavaScript code to show working of array.includes() function:
Code #1:
<script> // Taking input as an array A // having some elements. var A = [ 1, 2, 3, 4, 5 ]; // include() function is called to // test whether the searching element // is present in given array or not. a = A.includes(2) // Printing result of function. document.write(a); </script> |
Output:
true
Code #2:
<script> // Taking input as an array A // having some elements. var name = [ 'gfg', 'cse', 'geeks', 'portal' ]; // include() function is called to // test whether the searching element // is present in given array or not. a = name.includes('cat') // Printing result of function document.write(a); </script> |
Output:
false
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- JavaScript | Array.of() function
- JavaScript | Math.E() function
- JavaScript | toString( ) function
- JavaScript | Function Apply
- JavaScript | Function Definitions
- JavaScript | Function Parameters
- JavaScript | Array every() function
- JavaScript | Array some() function
- JavaScript | Function Invocation
- What is the inline function in JavaScript ?
- JavaScript | String() Function
- JavaScript | toPrecision( ) Function
- Javascript | Number() Function
- JavaScript | toExponential() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet



