主题
dropRightWhile
js
_.dropRightWhile(array, [predicate=_.identity])
创建 array
的一个切片,不包括从结尾删除的元素。元素将被删除,直到 predicate
返回 falsey。使用三个参数调用谓词:(value, index, array)。
¥Creates a slice of array
excluding elements dropped from the end. Elements are dropped until predicate
returns falsey. The predicate is invoked with three arguments: (value, index, array).
新增于
¥Since
3.0.0
参数
¥Arguments
array
(数组):要查询的数组。¥
array
(Array): The array to query.[predicate=_.identity]
(函数):每次迭代调用的函数。¥
[predicate=_.identity]
(Function): The function invoked per iteration.
返回
¥Returns
(数组):返回 array
的切片。
¥(Array): Returns the slice of array
.
示例
¥Example
js
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
_.dropRightWhile(users, function(o) { return !o.active; });
// => objects for ['barney']
// The `_.matches` iteratee shorthand.
_.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
// => objects for ['barney', 'fred']
// The `_.matchesProperty` iteratee shorthand.
_.dropRightWhile(users, ['active', false]);
// => objects for ['barney']
// The `_.property` iteratee shorthand.
_.dropRightWhile(users, 'active');
// => objects for ['barney', 'fred', 'pebbles']