Skip to content

Function: mapKeys()

ts
function mapKeys<T>(object, iteratee): Record<string, T[keyof T]>;

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

Type Parameters

Type ParameterDescription
T extends Record<string, unknown>The source object type / 源对象类型

Parameters

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

Returns

Record<string, T[keyof T]>

A new object with transformed keys / 键转换后的新对象

Example

ts
mapKeys({ a: 1, b: 2 }, (key) => key.toUpperCase())
// => { A: 1, B: 2 }

Since

1.2.0

Released under the MIT License.