Lodash _.mapValues() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Creates an object with the same keys as object and values generated by running each own enumerable string key through iteratee. Part of Lodash Object since 0.8.3 (stable — not deprecated).

Note: Key insertion order in the result follows own enumerable string keys; do not rely on a specific order across older engines.

Syntax

Call _.mapValues. Start with this line.

Lodash
_.mapValues(object, [iteratee])
CallWhat it does
_.mapValues(object, [iteratee])Primary signature.
_.mapValues(object)Work with an object’s keys, values, or paths.

Prefer import mapValues from "lodash/mapValues" when you want a smaller bundle.

Library declarations
Lodash
_.mapValues(object, [iteratee])

Parameters

This method has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*New object (source not mutated)

Lodash Examples

Example 1 — Official: Property Shorthand

Pluck one field from each nested value with a string iteratee.

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

_.mapValues(users, 'age');
// → { fred: 40, pebbles: 1 }
Try It Yourself

How It Works

  1. Shorthand. 'age' means “read .age from each value”.
  2. fred. Value is {user:'fred', age:40} → new value 40.
  3. pebbles. Same pattern → 1.
  4. Keys. Still fred and pebbles.

Example 2 — Official: Function Iteratee

Return a field with an explicit function — same idea as the shorthand.

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

_.mapValues(users, function(o) {
  return o.user;
});
// → { fred: 'fred', pebbles: 'pebbles' }
Try It Yourself

How It Works

  1. Iteratee. Receives each nested object as o.
  2. Return. o.user becomes the new value.
  3. Keys. Unchanged (fred, pebbles).
  4. Vs shorthand. Same result as _.mapValues(users, 'user').

Example 3 — Square Numbers

Transform plain numeric values with a function.

Lodash
_.mapValues({ a: 1, b: 2 }, function(value) {
  return value * value;
});
// → { a: 1, b: 4 }
Try It Yourself

How It Works

  1. a. 1 * 1 → 1.
  2. b. 2 * 2 → 4.
  3. Keys. Still a and b.
  4. Use. Scale, format, or derive values in place.

Example 4 — Use Key and Value

The iteratee also receives the key — build labeled strings.

Lodash
_.mapValues({ a: 1, b: 2 }, function(value, key) {
  return key + ':' + value;
});
// → { a: 'a:1', b: 'b:2' }
Try It Yourself

How It Works

  1. Args. Iteratee is (value, key, object).
  2. a. Builds 'a:1'.
  3. b. Builds 'b:2'.
  4. Keys. Unchanged; only values are strings now.

Example 5 — mapValues vs mapKeys

Same source; rewrite values or rewrite keys.

Lodash
var obj = { a: 1, b: 2 };

_.mapValues(obj, function(v) { return v * 10; });
// → { a: 10, b: 20 }

_.mapKeys(obj, function(v, k) { return k.toUpperCase(); });
// → { A: 1, B: 2 }
Try It Yourself

How It Works

  1. mapValues. Values × 10; keys stay.
  2. mapKeys. Keys become uppercase; values stay.
  3. Pair. Chain both when you need to reshape both sides.
  4. Pick. Choose the helper that matches what must change.

Browser & Runtime Support

_.mapValues is a Lodash Object helper since 0.8.3. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.8.3+

_.mapValues()

Available in [email protected] full builds and the lodash/mapValues modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 0.8.3+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.mapValues Lodash 0.8.3+

Bottom line: Safe for production once Lodash is loaded. Prefer import mapValues from "lodash/mapValues" for smaller bundles. Use it to transform object values without mutating the source.

Frequently Asked Questions

_.mapValues(object, [iteratee]) creates a new object with the same keys and values produced by iteratee. Official: _.mapValues(users, 'age') → {fred:40, pebbles:1}.
It is called as (value, key, object) for each own enumerable string-keyed property. Whatever it returns becomes the new value at that key.
No. It always returns a new object. The source is left unchanged.
Function, property name string (e.g. 'age'), path arrays, and matchers — same iteratee shortcuts as other Lodash collection helpers.
mapValues keeps keys and rewrites values. mapKeys keeps values and rewrites keys.
Use import mapValues from "lodash/mapValues" or require("lodash/mapValues") for tree-shaking. Full build: import _ from "lodash" then _.mapValues.

Next: _.merge()

Recursively merge source objects into a destination.

_.merge() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful