mapKeys
Returns a new object by transforming each key of the given object according to the result of the provided iteratee function.
Code
Benchmark
hz: operations per secondmean: average response time (ms)
| Name | hz | mean | Performance |
|---|---|---|---|
| modern-kit/mapKeys | 3,983,407.38 | 0.0003 | fastest |
| lodash/mapKeys | 3,060,203.94 | 0.0003 | slowest |
- modern-kit/mapKeys
1.30xfaster 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 }