Skip to main content
Module

std/collections/mod.ts>mapKeys

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

Applies the given transformer to all keys in the given record's entries and returns a new record containing the transformed entries.

If the transformed entries contain the same key multiple times, only the last one will appear in the returned record.

Example:

const counts = { a: 5, b: 3, c: 8 }

console.assert(mapKeys(counts, it => it.toUppercase()) === {
    A: 5,
    B: 3,
    C: 8,
})

Parameters

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

Returns

Record<string, T>