Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function mapValues
import { mapValues } from "https://deno.land/std@0.147.0/collections/map_values.ts";

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.147.0/collections/map_values.ts";
import { assertEquals } from "https://deno.land/std@0.147.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>>
transformer: (value: T) => O

Returns

Record<string, O>