Skip to main content

every

_.every(predicate, collection) # Ⓢ [Ⓣ][1] Ⓝ

Checks if predicate returns truthy for all elements of collection.



Iteration is stopped once predicate returns falsey. The predicate is



invoked with three arguments: (value, index|key, collection).





Note: This method returns true for



empty collections because



everything is true of



elements of empty collections.

Since​

0.1.0

Arguments​

  1. predicate (Function): The function invoked per iteration.
  2. collection (Array|Object): The collection to iterate over.

Returns​

(boolean): Returns true if all elements pass the predicate check,



else false.

Example​

_.every(Boolean, [true, 1, null, 'yes']);
// => false

var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': false }
];

// The `_.matches` iteratee shorthand.
_.every({ 'user': 'barney', 'active': false }, users);
// => false

// The `_.matchesProperty` iteratee shorthand.
_.every(['active', false], users);
// => true

// The `_.property` iteratee shorthand.
_.every('active', users);
// => false