Skip to main content
This release is 5 versions behind 1.33.0 — the latest version of @es-toolkit/es-toolkit. Jump to latest

@es-toolkit/es-toolkit@1.29.0-dev.958+1d1d0ee6
Built and signed on GitHub Actions

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (1.29.0-dev.958+1d1d0ee6)
function mapValues
mapValues<
T extends object,
K extends keyof T,
V,
>
(
object: T,
getNewValue?:
PropertyKey
| readonly PropertyKey[]
| null
| undefined
,
): Record<K, V>

Creates a new object with the same keys as the given object, but with values generated by running each own enumerable property of the object through the iteratee function.

Examples

Example 1

// Example usage: const obj = { a: 1, b: 2 }; const result = mapValues(obj, (value) => value * 2); console.log(result); // { a: 2, b: 4 }

Type Parameters

T extends object
  • The type of the object.
K extends keyof T
  • The type of the keys in the object.
  • The type of the new values generated by the iteratee function.

Parameters

object: T
  • The object to iterate over.
optional
getNewValue:
PropertyKey
| readonly PropertyKey[]
| null
| undefined
  • The function invoked per own enumerable property.

Return Type

Record<K, V>
  • Returns the new mapped object.
mapValues<
T extends object,
K extends keyof T,
V,
>
(
object: T,
getNewValue: (
value: T[K],
key: K,
object: T,
) => V
,
): Record<K, V>

Creates a new object with the same keys as the given object, but with values generated by running each own enumerable property of the object through the iteratee function.

Examples

Example 1

// Example usage: const obj = { a: 1, b: 2 }; const result = mapValues(obj, (value) => value * 2); console.log(result); // { a: 2, b: 4 }

Type Parameters

T extends object
  • The type of the object.
K extends keyof T
  • The type of the keys in the object.
  • The type of the new values generated by the iteratee function.

Parameters

object: T
  • The object to iterate over.
getNewValue: (
value: T[K],
key: K,
object: T,
) => V
  • The function invoked per own enumerable property.

Return Type

Record<K, V>
  • Returns the new mapped object.

Add Package

deno add jsr:@es-toolkit/es-toolkit

Import symbol

import { mapValues } from "@es-toolkit/es-toolkit/compat";

---- OR ----

Import directly with a jsr specifier

import { mapValues } from "jsr:@es-toolkit/es-toolkit/compat";

Add Package

npx jsr add @es-toolkit/es-toolkit

Import symbol

import { mapValues } from "@es-toolkit/es-toolkit/compat";

Add Package

yarn dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { mapValues } from "@es-toolkit/es-toolkit/compat";

Add Package

pnpm dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { mapValues } from "@es-toolkit/es-toolkit/compat";

Add Package

bunx jsr add @es-toolkit/es-toolkit

Import symbol

import { mapValues } from "@es-toolkit/es-toolkit/compat";