Module

std/collections/mod.ts>mapEntries

Deno standard library
Go to Latest
function mapEntries
import { mapEntries } from "https://dotland.deno.dev/std@0.130.0/collections/mod.ts";

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

Example:

import { mapEntries } from "https://deno.land/std@0.130.0/collections/mod.ts";
import { assertEquals } from "https://deno.land/std@0.130.0/testing/asserts.ts";

const usersById = {
    'a2e': { name: 'Kim', age: 22 },
    'dfe': { name: 'Anna', age: 31 },
    '34b': { name: 'Tim', age: 58 },
} as const;

const agesByNames = mapEntries(usersById,
    ([ id, { name, age } ]) => [ name, age ],
)

assertEquals(agesByNames, {
    'Kim': 22,
    'Anna': 31,
    'Tim': 58,
})

Parameters

record: Readonly<Record<string, T>>
transformer: (entry: [string, T]) => [string, O]

Returns

Record<string, O>
import mapEntries
import { mapEntries } from "https://dotland.deno.dev/std@0.130.0/collections/mod.ts";