Lodash every method
语法:
_.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).
参数:
collection (Array|Object) − The collection to iterate over.
[predicate=_.identity] (Function) − The function invoked per iteration.
输出:
(boolean) − Returns true if all elements pass the predicate check, else false.
例子:
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.
命令:
输出: