How to use JavaScript Array includes()

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

  1. Declare two variable a and b
  2. Initialize two variable a and b with value of array a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'] and b = a.includes('Lion')
  3. Array includes() method checks the statement in all elements of the given array, returns true if found, false if not found
  4. The value of b variable is displayed with the help of console.log inbuilt function

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

  1. Declare two variable c and d
  2. Initialize two variable c and d with value of array c = [1,2,3,4,5] and d = c.includes(8)
  3. Array includes() method checks the statement in all elements of the given array, returns true if found, false if not found
  4. The value of d variable is displayed with the help of console.log inbuilt function