Skip to content

takeRightWhile

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

创建 array 的一个切片,其中从结尾获取了元素。元素被获取,直到 predicate 返回 falsey。使用三个参数调用谓词:(value, index, array)。

¥Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

新增于

¥Since

3.0.0

参数

¥Arguments

  1. array (数组):要查询的数组。

    ¥array (Array): The array to query.

  2. [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 }
];

_.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');
// => []

Lodash v4.17 中文网 - 粤ICP备13048890号