阅读(1990) (0)

Lodash _.takeRightWhile

2021-09-17 17:24:34 更新

_.takeRightWhile(array, [predicate=_.identity])

从array数组的最后一个元素开始提取元素,直到 predicate 返回假值。predicate 会传入三个参数: (value, index, array)。

添加版本

3.0.0

参数

  1. array (Array): 要检索的数组。
  2. [predicate=_.identity] (Array|Function|Object|string): 每次迭代调用的函数。

返回

(Array): 返回 array 数组的切片。

例子

var users = [  { 'user': 'barney',  'active': true },  { 'user': 'fred',    'active': false },  { 'user': 'pebbles', 'active': false }]; 
_.takeRightWhile(users, function(o) { return !o.active; });
// => objects for ['fred', 'pebbles'] 
// The `_.matches` iteratee shorthand.
_.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
// => objects for ['pebbles'] 
// The `_.matchesProperty` iteratee shorthand.
_.takeRightWhile(users, ['active', false]);
// => objects for ['fred', 'pebbles']
// The `_.property` iteratee shorthand.
_.takeRightWhile(users, 'active');
// => []