map
Transforms the values and/or keys of a plain object in a single pass.
Both callbacks are optional and default to identity (no transformation).
When mapValue is omitted the original values are preserved;
when mapKey is omitted the original keys are preserved.
Note: if two different keys map to the same output key the last one wins
(insertion order). Entries whose mapped key is a prototype-polluting string
(__proto__, constructor, prototype) are silently skipped.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
obj | TObj | null | undefined | The source object |
mapValue | function | Callback called with (value, key) for each entry. Defaults to identity. (optional) |
mapKey | function | Callback called with (key, value) for each entry. Defaults to identity. (optional) |
Returns
Section titled “Returns”Record<TKey, TVal> — A new object with transformed keys and/or values
Examples
Section titled “Examples”Transform values
Section titled “Transform values”Maps each value of an object through a transform function.
Transform keys
Section titled “Transform keys”Maps each key of an object through a transform function.
Transform both keys and values in a single pass
Section titled “Transform both keys and values in a single pass”Provide both a value mapper and a key mapper to rewrite the whole object.
