Skip to main content

mapValues

Returns a new object by transforming each value 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/mapValues6,203,964.880.0003fastest
lodash/mapValues4,557,524.770.0004slowest
  • modern-kit/mapValues
    • 1.36x faster than lodash/mapValues

Interface

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

Usage

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

const users = {
fred: { user: 'fred', age: 40 },
pebbles: { user: 'pebbles', age: 1 }
};

const newUsers = mapValues(users, ({ value }) => value.age);
// { fred: 40, pebbles: 1 }