Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

mapValues

Creates a new object with the same keys as the input object, but with values transformed by the provided callback function. Similar to Array.prototype.map() but for object values.

@example
const prices = { apple: 1, banana: 2, orange: 3 }
const doubled = mapValues(prices, (price) => price * 2)
// Result: { apple: 2, banana: 4, orange: 6 }
@example
const users = { john: 25, jane: 30, bob: 35 }
const greetings = mapValues(users, (age, name) => `${name} is ${age} years old`)
// Result: { john: 'john is 25 years old', jane: 'jane is 30 years old', bob: 'bob is 35 years old' }
@example
const data = { a: '1', b: '2', c: '3' }
const numbers = mapValues(data, (str) => parseInt(str, 10))
// Result: { a: 1, b: 2, c: 3 }
function mapValues<ValueIn, ValueOut>(object: Record<string, ValueIn>, callback: (value: ValueIn, key: string) => ValueOut): Record<string, ValueOut>;
§
mapValues<ValueIn, ValueOut>(object: Record<string, ValueIn>, callback: (value: ValueIn, key: string) => ValueOut): Record<string, ValueOut>
[src]

§Type Parameters

§
ValueIn
[src]
§
ValueOut
[src]

§Parameters

§
object: Record<string, ValueIn>
[src]
  • The object whose values will be transformed.
§
callback: (value: ValueIn, key: string) => ValueOut
[src]
  • A function that transforms each value. Receives the value and its corresponding key as arguments.

§Return Type

§
Record<string, ValueOut>
[src]

A new object with the same keys but transformed values.