Lodash - findLastKey method


Advertisements

Syntax

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

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

Arguments

  • object (Object) − The object to inspect.

  • [predicate=_.identity] (Function) − The function invoked per iteration.

Output

  • (*) − Returns the key of the matched element, else undefined..

Example

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);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

Stefan
lodash_object.htm
Advertisements