更新时间:2023-02-09 13:00:09
带有下划线
Underscore提供了 _.mapObject
函数来映射值并保留键.
Underscore provides a function _.mapObject
to map the values and preserve the keys.
_.mapObject({ one: 1, two: 2, three: 3 }, function (v) { return v * 3; });
// => { one: 3, two: 6, three: 9 }
使用 Lodash
Lodash提供了 _.mapValues
函数来映射值并保留键.
Lodash provides a function _.mapValues
to map the values and preserve the keys.
_.mapValues({ one: 1, two: 2, three: 3 }, function (v) { return v * 3; });
// => { one: 3, two: 6, three: 9 }