function mapValues
mapValues<T extends Record<string, unknown>, V>(
obj: T | None,
fn: (
value: T[keyof T],
key: keyof T
) => V
): [K in keyof T]: V

Returns a new object with the same keys, where each value is transformed by fn.

Examples

Example 1

mapValues({ a: 1, b: 2 }, (v) => v * 2); // { a: 2, b: 4 }
mapValues({ a: 1, b: 2 }, (v, k) => `${k}=${v}`); // { a: "a=1", b: "b=2" }
mapValues(null, (v) => v); // {}

Type Parameters

T extends Record<string, unknown>

Parameters

obj: T | None
fn: (
value: T[keyof T],
key: keyof T
) => V

Return Type

[K in keyof T]: V

Usage

import { mapValues } from ".";