dynamic-forms / Function

mapValues

Generic types:T U

Maps object values through a transformation function Native replacement for lodash mapValues()

Presentation

function mapValues(
  obj: Record<string, T>,
  fn: (value: T, key: string) => U,
): Record<string, U>;

Returns

Record<string, U> -

New object with transformed values

Parameters

NameTypeDescription
obj
Record<string, T>

Source object

fn
(value: T, key: string) => U

Transformation function

Example usage

const obj = { a: 1, b: 2 };
mapValues(obj, (v) => v * 2); // { a: 2, b: 4 }