Lodash dropWhile method
语法:
_.dropWhile(array, [predicate=_.identity])
Creates a slice of array excluding elements dropped from the beginning. Elements are dropped until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).
参数
array (Array) − The array to query.
[predicate=_.identity] (Function) − The function invoked per iteration.
输出:
(Array) − Returns the slice of array.
实例:
var _ = require('lodash');
var users = [
{ user: 'Sam', active: false },
{ user: 'Ted', active: true },
{ user: 'Julie', active: false }
];
var result = _.dropWhile(users, function(user) { return !user.active; });
console.log(result);
result = _.dropWhile(users, ['active', false]);
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
命令:
输出:
[ { user: 'Ted', active: true }, { user: 'Julie', active: false } ]
[ { user: 'Ted', active: true }, { user: 'Julie', active: false } ]