Skip to content

mapValues

Creates a new Map with the same keys but with each value transformed by a function.

Available since v3.0.3

import { mapValues } from '@helpers4/map';
// or, from the all-in-one package (same code, one install):
import { mapValues } from 'helpers4/map';
mapValues<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<K, R>
ParameterTypeDescription
mapReadonlyMap<K, V>The Map to transform
fnfunctionFunction invoked with (value, key) that returns the new value

Map<K, R> — A new Map with transformed values

Creates a new Map with transformed values and unchanged keys.

mapValues(new Map([['a', 1], ['b', 2]]), value => value * 10)
// => Map(2) { 'a' => 10, 'b' => 20 }

View source on GitHub