Skip to main content
Module

std/collections/mod.ts>mapValues

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

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

Example:

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

console.assert(namesById === {
    'a5ec': 'Mischa',
    'de4f': 'Kim',
}

Parameters

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

Returns

Record<string, O>