std/collections/mod.ts

Deno standard library
Go to Latest
function mapValues
import { mapValues } from "https://deno.land/std@0.139.0/collections/mod.ts?s=mapValues";

Applies the given transformer to all values in the given record and returns a new record containing the resulting keys associated to the last value that produced them.

Example:

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

const usersById = {
    'a5ec': { name: 'Mischa' },
    'de4f': { name: 'Kim' },
}
const namesById = mapValues(usersById, it => it.name)

assertEquals(namesById, {
    'a5ec': 'Mischa',
    'de4f': 'Kim',
});

Parameters

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

Returns

Record<string, O>[src]
import mapValues
import { mapValues } from "https://deno.land/std@0.139.0/collections/mod.ts?s=mapValues";