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
Pingback: Lodash - count By method - Adglob Infosystem Pvt Ltd
Pingback: Lodash - sortBy method - Adglob Infosystem Pvt Ltd