mapEntries
@guoba-ai/utils / object / mapEntries
Function: mapEntries()
function mapEntries<T, K, V>(obj, fn): Record<K, V>;Defined in: object.ts:306
Transform both keys and values of an object using a mapping function.
Parameters
obj
T
The source object
fn
(key, value) => [K, V]
Function that receives each key and value, returns a [newKey, newValue] tuple
Returns
Record<K, V>
A new object with transformed keys and values
Example
mapEntries({ a: 1, b: 2 }, (key, value) => [key.toUpperCase(), value * 10])
// { A: 10, B: 20 }
mapEntries({ name: 'alice', age: '30' }, (key, value) => [value, key])
// { alice: 'name', 30: 'age' }
mapEntries({ a: 1, b: 2 }, (_key, value) => ['same', value])
// { same: 2 }Warning
If the mapping function returns the same key for multiple entries, the later value wins.