Lodash – every method

  • Post author:
  • Post category:Lodash
  • Post comments:2 Comments
Lodash - every method

Syntax Of Lodash every method

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

Lodash every method checks if the predicate returns truthy for all elements of the collection. Iteration is stopped once predicate returns falsely.

Arguments

  • collection (Array|Object) − The collection to iterate over.
  • [predicate=_.identity] (Function) − The function invoked per iteration.

Output

  • (boolean) − Returns true if all elements pass the predicate check, else false.

Example

var _ = require('lodash');
var list = [
   { 'user': 'Joe', 'age': 36, 'active': false },
   { 'user': 'Jake', 'age': 40, 'active': false }
];
 
var result = _.every(list, ['active', false]);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

true

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply