How to use JavaScript Array every()

Program to use JavaScript Array every() method


function evennumber(number) {
    return number % 2 == 0;
}
let a = [3, 5, 7, 23, 13];
let b = a.every(evennumber);
console.log(b);

Output


false

Steps Description

  1. Declare function evennumber
  2. Declare two variables a and b
  3. Initialize two variables a and b with value of string a = [3, 5, 7, 23, 13] and b = a.every(evennumber)
  4. Array every() method checks array every element and returns boolean value
  5. The value of b variable is displayed with the help of console.log inbuilt function