Lodash教程

Lodash mapKeys method

语法

_.mapKeys(object, [iteratee=_.identity])
The opposite of _.mapValues; this method creates an object with the same values as object and keys generated by running each own enumerable string keyed property of object thru iteratee. The iteratee is invoked with three arguments: (value, key, object).

参数

object (Object) − The object to iterate over. [iteratee=_.identity] (Function) − The function invoked per iteration.

输出

(Object) − Returns the new mapped object.

实例

var _ = require('lodash');
var object = { 'a': 1, 'b': 2 };
var result = _.mapKeys(object, function(value, key) {
   return key + value;
});
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

{ a1: 1, b2: 2 }
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4