Maps the values of an object and constructs a new object with the same keys.
Only own enumerable string keys are processed; symbol keys are ignored. The input object is not mutated.
映射对象的值,并构造一个具有相同键的新对象。
仅处理自身可枚举的字符串键,符号键会被忽略。不会修改输入对象。
The type of the values in the source object. 源对象中值的类型
The type of the values in the result object. 结果对象中值的类型
The source object. 源对象
The function to transform each value. 用于转换每个值的函数
A new object with the same keys and transformed values. 具有相同键和转换后值的新对象
All keys are preserved, including dangerous keys such as __proto__. Keys are created as own data properties via Object.fromEntries, so no prototype pollution occurs.
__proto__
Object.fromEntries
所有键都会被保留,包括 __proto__ 等危险键。键通过 Object.fromEntries 作为自身数据属性创建,因此不会发生原型污染。
mapValues({ a: 1, b: 2 }, (v) => v * 2)// => { a: 2, b: 4 } Copy
mapValues({ a: 1, b: 2 }, (v) => v * 2)// => { a: 2, b: 4 }
mapValues({ a: 1, b: 2 }, (v, k) => k + v)// => { a: 'a1', b: 'b2' } Copy
mapValues({ a: 1, b: 2 }, (v, k) => k + v)// => { a: 'a1', b: 'b2' }
Maps the values of an object and constructs a new object with the same keys.
Only own enumerable string keys are processed; symbol keys are ignored. The input object is not mutated.
映射对象的值,并构造一个具有相同键的新对象。
仅处理自身可枚举的字符串键,符号键会被忽略。不会修改输入对象。