Lodash教程

Lodash findKey method

语法

_.findKey(object, [predicate=_.identity])
This method is like _.find except that it returns the key of the first element predicate returns truthy for instead of the element itself.

参数

object (Object) − The object to inspect. [predicate=_.identity] (Function) − The function invoked per iteration.

输出

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

实例

var _ = require('lodash');
var users = {
   'Joe': { 'age': 36, 'active': true },
   'Robert': { 'age': 40, 'active': false },
   'Stefan': { 'age': 10,   'active': true }
};
var result = _.findKey(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

输出

Joe
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4