Skip to content

findLastKey

js
_.findLastKey(object, [predicate=_.identity])

此方法与 _.findKey 类似,不同之处在于它以相反的顺序迭代集合的元素。

¥This method is like _.findKey except that it iterates over elements of a collection in the opposite order.

新增于

¥Since

2.0.0

参数

¥Arguments

  1. object (对象):要反转的对象。

    ¥object (Object): The object to inspect.

  2. [predicate=_.identity] (函数):每次迭代调用的函数。

    ¥[predicate=_.identity] (Function): The function invoked per iteration.

返回

¥Returns

(*):返回匹配元素的键,否则为 undefined

¥()*: Returns the key of the matched element, else undefined.

示例

¥Example

js
var users = {
  'barney':  { 'age': 36, 'active': true },
  'fred':    { 'age': 40, 'active': false },
  'pebbles': { 'age': 1,  'active': true }
};

_.findLastKey(users, function(o) { return o.age < 40; });
// => returns 'pebbles' assuming `_.findKey` returns 'barney'

// The `_.matches` iteratee shorthand.
_.findLastKey(users, { 'age': 36, 'active': true });
// => 'barney'

// The `_.matchesProperty` iteratee shorthand.
_.findLastKey(users, ['active', false]);
// => 'fred'

// The `_.property` iteratee shorthand.
_.findLastKey(users, 'active');
// => 'pebbles'

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