How to use JavaScript Array includes()
Array includes
On this page
Array includes() Method
Program to use JavaScript Array includes() method
let a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let b = a.includes('Lion');
console.log(b);
Output
true
Steps Description
- Declare two variable a and b
- Initialize two variable a and b with value of array a = [‘Cat’, ‘Dog’, ‘Tiger’, ‘Lion’, ‘Elephant’] and b = a.includes(‘Lion’)
- Array includes() method checks the statement in all elements of the given array, returns true if found, false if not found
- The value of b variable is displayed with the help of console.log inbuilt function
Array includes() Method
Program to use JavaScript Array includes() method
let c = [1,2,3,4,5];
let d = c.includes(8);
console.log(d);
Output
false
Steps Description
- Declare two variable c and d
- Initialize two variable c and d with value of array c = [1,2,3,4,5] and d = c.includes(8)
- Array includes() method checks the statement in all elements of the given array, returns true if found, false if not found
- The value of d variable is displayed with the help of console.log inbuilt function