Lodash - findLastKey 方法



語法

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

此方法類似於 _.findKey,只不過它以相反的順序迭代集合的元素。

引數

  • object (Object) − 要檢查的物件。

  • [predicate=_.identity] (Function) − 每進行一次迭代呼叫的函式。

輸出

  • (*) − 返回匹配的元素的鍵,否則為未定義。

示例

var _ = require('lodash');
 
var users = {
   'Joe': { 'age': 36, 'active': true },
   'Robert': { 'age': 40, 'active': false },
   'Stefan': { 'age': 10,   'active': true }
};

var result = _.findLastKey(users, function(o) { return o.age < 40; });
console.log(result);

在 **tester.js** 中儲存上述程式。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

Stefan
lodash_object.htm
廣告
© . All rights reserved.