Skip to content

Function: mapValues()

ts
function mapValues<T, R>(object, iteratee): Record<string, R>;

Creates a new object with transformed values. 创建一个值被转换后的新对象。

Type Parameters

Type ParameterDescription
T extends Record<string, unknown>The source object type / 源对象类型
RThe mapped value type / 映射后的值类型

Parameters

ParameterTypeDescription
objectTThe source object / 源对象
iteratee(value, key) => RThe value transform function / 值转换函数

Returns

Record<string, R>

A new object with transformed values / 值转换后的新对象

Example

ts
mapValues({ a: 1, b: 2 }, (value) => value * 2)
// => { a: 2, b: 4 }

Since

1.2.0

Released under the MIT License.