Skip to main content

mapKeys

Returns a new object by transforming each key of the given object according to the result of the provided iteratee function.


Code

🔗 View source code

Benchmark

  • hz: operations per second
  • mean: average response time (ms)
NamehzmeanPerformance
modern-kit/mapKeys3,983,407.380.0003fastest
lodash/mapKeys3,060,203.940.0003slowest
  • modern-kit/mapKeys
    • 1.30x faster than lodash/mapKeys

Interface

typescript
function mapKeys<T extends Record<PropertyKey, any>, K extends PropertyKey>(
obj: T,
iteratee: (iterateData: { key: keyof T; value: T[keyof T]; obj: T }) => K
): Record<K, T[keyof T]>;

Usage

typescript
import { mapKeys } from '@modern-kit/utils';

const obj = { a: 1, b: 2 };

const newObj = mapKeys(obj, ({ key, value }) => key + value);
// { a1: 1, b2: 2 }