Array.prototype.every

Determines whether all the elements of an array satisfy the specified test.

Syntax

every(predicate, thisArg?)

Parameters

Return value

Returns true if for all the elements of array the predicate function returned a truthy value, false otherwise.

Examples

[2, 4, 6].every(x => x % 2 == 0)
true
[2, 4, 6, 7].every(x => x % 2 == 0)
false
["moose", "monkey", "mouse"].every(s => s.startsWith("mo"))
true
["moose", "monkey", "cat"].every(s => s.startsWith("mo"))
false
function isUnique(value, index, array) {
   for (let [i, v] of array.entries()) {
      if (i != index && v == value) {
        return false
      }
   }
   return true
}

["apple", "orange", "banana"].every(isUnique)
true
["banana", "apple", "orange", "banana"].every(isUnique)
false

See also