all([iterator = Prototype.K[, context]]) -> Boolean

Determines whether all the elements are boolean-equivalent to true, either directly or through computation by the provided iterator.

The code obviously short-circuits as soon as it finds an element that “fails” (that is boolean-equivalent to false). If no iterator is provided, the elements are used directly. Otherwise, each element is passed to the iterator, and the result value is used for boolean equivalence.

The optional context parameter is what the iterator function will be bound to. If used, the this keyword inside the iterator will point to the object given by the argument.


// -> true (empty arrays have no elements that could be false-equivalent)

$R(1, 5).all()
// -> true (all values in [1..5] are true-equivalent)

[0, 1, 2].all()
// -> false (with only one loop cycle: 0 is false-equivalent)

[9, 10, 15].all(function(n) { return n >= 10; })
// -> false (the iterator will return false on 9)

$H({ name: 'John', age: 29, oops: false }).all(function(pair) { return pair.value; })
// -> false (the oops/false pair yields a value of false)

See also

If you need to determine whether at least one element matches a criterion, you would be better off using any.