Skip to main content
The Deno 2 Release Candidate is here
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function mapKeys
import { mapKeys } from "https://deno.land/std@0.159.0/collections/map_keys.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:

import { mapKeys } from "https://deno.land/std@0.159.0/collections/map_keys.ts";
import { assertEquals } from "https://deno.land/std@0.159.0/testing/asserts.ts";

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

assertEquals(mapKeys(counts, it => it.toUpperCase()), {
    A: 5,
    B: 3,
    C: 8,
})

Parameters

record: Readonly<Record<string, T>>
transformer: (key: string) => string

Returns

Record<string, T>