Horje
What is the use of the every() method in JavaScript Arrays ?

The every() method in JavaScript is used to check whether all elements in an array satisfy a particular condition. It returns a boolean value – true if all elements meet the specified condition, and false otherwise.

Example: Here, the every() method is used to check if every element in the numbers array is even. Since all elements in this case are even, the every() method returns true.

Javascript

let numbers = [2, 4, 6, 8, 10];
 
// Check if all numbers are even
let allEven = numbers.every(function(num) {
  return num % 2 === 0;
});
 
console.log(allEven); // Output: true

Output

true




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
How to Convert an Array to a String in JavaScript ? How to Convert an Array to a String in JavaScript ?
What is the use of the Array.of() method in JavaScript ? What is the use of the Array.of() method in JavaScript ?
What is a Sparse Array in JavaScript ? What is a Sparse Array in JavaScript ?
What is the use of reverse() method in JavaScript Arrays ? What is the use of reverse() method in JavaScript Arrays ?
What is a WeakMap Object in JavaScript ? What is a WeakMap Object in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14