Describing the every
Operation
- The
every
operation is used for testing if every element of an array satisfies a condition -
It accepts a callback function with the following arguments:
currentValue:
Current element processed in the arrayindex
: Optional index ofcurrentValue
array
: Optional array that is calledthisArg
: Optional value to use asthis
Defining an Array
let fruits = ["Apple", "Banana"];
console.log(fruits.length);
// 2
Using the every
Operation
// Regular function
fruits.every(function(item, index, array) {
return item.length > 10;
})
// false
// Arrow function
fruits.every(item => item.length > 2);
// true
Previous
Next