every source npm

_.every(collection, [predicate=_.identity])

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).

Arguments

  1. collection (Array|Object)

    The collection to iterate over.

  2. [predicate=_.identity] (Function|Object|string)

    The function invoked per iteration.

Returns (boolean)

Returns true if all elements pass the predicate check, else false.

Example

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

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

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

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

// using the `_.property` callback shorthand
_.every(users, 'active');
// => false