Skip to content

mapObj

mapObj<T, U>(obj, fn): Record<string, U>

Defined in: object/map-obj.ts:17

Applies a mapping function to each value in an object and returns a new object with the mapped values.

Type Parameters

T

T

U

U

Parameters

obj

Record<string, T>

The input object to map over.

fn

(value, key) => U

The mapping function that takes a value and its key, and returns a new value.

Returns

Record<string, U>

A new object with the same keys as the input object, but with values transformed by the mapping function.

Example

const original = { a: 1, b: 2, c: 3 };
const mapped = mapObj(original, (value, key) => value * 2);
// mapped is { a: 2, b: 4, c: 6 }