Determines whether all the elements of an array satisfy the specified test.
every(predicate, thisArg?)
predicate function(value, index, array)
A function that accepts value, index, and array. It is called for every element of the array until it returns a falsy value or until the end of the array.
thisArg optional
An object to which the this keyword is bound in the predicate function. If omitted, undefined is used as the this value.
Returns true if for all the elements of array the predicate function
returned a truthy value, false otherwise.
[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