Skip to main content
Go to Latest
function mapEntries
import { mapEntries } from "https://deno.land/std@0.102.0/collections/map_entries.ts";

Applies the given transformer to all entries in the given record and returns a new record containing the results

Example:

const usersById = {
    'a2e': { name: 'Kim', age: 22 },
    'dfe': { name: 'Anna', age: 31 },
    '34b': { name: 'Tim', age: 58 },
}
const agesByNames = mapEntries(usersById,
    ([ id, { name, age } ]) => [ name, age ],
)

console.assert(agesByNames === {
    'Kim': 22,
    'Anna': 31,
    'Tim': 58,
})

Parameters

record: Record<string, T>
transformer: Selector<[string, T], [string, O]>

Returns

Record<string, O>