主题
mapKeys
js
_.mapKeys(object, [iteratee=_.identity])
选项对象。此方法创建一个对象,其值与 object
相同,并且通过运行 object
至 iteratee
的每个可枚举字符串键控属性生成键。迭代器使用三个参数调用:(value, key, object)。
¥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).
新增于
¥Since
3.8.0
参数
¥Arguments
object
(对象):要迭代的对象。¥
object
(Object): The object to iterate over.[iteratee=_.identity]
(函数):每次迭代调用的函数。¥
[iteratee=_.identity]
(Function): The function invoked per iteration.
返回
¥Returns
(对象):返回新的映射对象。
¥(Object): Returns the new mapped object.
示例
¥Example
js
_.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
return key + value;
});
// => { 'a1': 1, 'b2': 2 }