For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/object/mapKeysAsync.md.

mapKeysAsync es-toolkit

Returns a new object with keys transformed through an async function.

const newObj = await mapKeysAsync(object, getNewKey);

Usage

mapKeysAsync(object, getNewKey, options?)

Use mapKeysAsync when you want to create a new object by asynchronously transforming each key. Values remain the same, and each key is replaced with the value inside the Promise returned by the getNewKey function.

import { mapKeysAsync } from 'es-toolkit/object';

// Add prefix to keys
const obj = { a: 1, b: 2 };
const prefixed = await mapKeysAsync(obj, async (value, key) => `prefix_${key}`);
// prefixed becomes { prefix_a: 1, prefix_b: 2 }

// Combine key and value to create new keys
const combined = await mapKeysAsync(obj, async (value, key) => `${key}${value}`);
// combined becomes { a1: 1, b2: 2 }

// Convert keys to uppercase
const uppercased = await mapKeysAsync(obj, async (value, key) => key.toString().toUpperCase());
// uppercased becomes { A: 1, B: 2 }

// Limit concurrency
await mapKeysAsync(obj, async (value, key) => await processKey(key, value), { concurrency: 2 });
// Only 2 keys are processed concurrently at most

Parameters

objectT extends Record<PropertyKey, any>required

The object to transform keys from.

getNewKey(value: T[keyof T], key: keyof T, object: T) => Promise<K>required

An async function that generates new keys. Receives value, key, and the entire object as parameters.

optionsMapKeysAsyncOptionsoptional

Options to control concurrency.

  • concurrency (number, optional): Maximum number of concurrent operations. If not specified, all operations run concurrently.

Returns

Returns a promise that resolves to a new object with transformed keys.

Promise<Record<K, T[keyof T]>>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.