GuobaGuoba Utils

mapKeys

@guoba-ai/utils / object / mapKeys

Function: mapKeys()

function mapKeys<T, K>(obj, fn): Record<K, T[keyof T]>;

Defined in: object.ts:195

Transform the keys of an object using a mapping function.

Type Parameters

T

T extends object

K

K extends string

Parameters

obj

T

The source object

fn

(key, value) => K

Function that receives each key and value, returns the new key

Returns

Record<K, T[keyof T]>

A new object with transformed keys

Example

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

On this page