Underscore.js _.mapObject() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Like map, but for objects — transform the value of each property in turn (official Underscore docs). Returns a new object with the same keys. Stable helper — not deprecated.

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.mapObject. Start with this line.

Underscore
_.mapObject(object, iteratee, [context])
CallWhat it does
_.mapObject(object, iteratee, [context])Primary signature.
_.mapObject(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.mapObject(object, iteratee, [context])

Parameters

ParameterDescription
objectRequired. Source whose values you transform
iterateeRequired. Function, or property-name string
contextOptional. Value of this for the iteratee

Return Value

Return ValueDescription
*New object; same keys, new values

Underscore.js Examples

Example 1 — Official: Add 5 to Each Value

The docs keep start and end, and bump each number by 5.

Underscore
_.mapObject({start: 5, end: 12}, function (val, key) {
  return val + 5;
});
// → {start: 10, end: 17}
Try It Yourself

How It Works

  1. Source. Two own properties: start: 5 and end: 12.
  2. Iteratee. For each value, return val + 5.
  3. Keys stay. Result still has start and end.
  4. Official result. {start: 10, end: 17}.

Example 2 — Double Every Value

Scale numbers while keeping product names as keys.

Underscore
var prices = {apple: 30, milk: 50, bread: 20};

_.mapObject(prices, function (value) {
  return value * 2;
});
// → {apple: 60, milk: 100, bread: 40}
Try It Yourself

How It Works

  1. Input. A prices object with three own keys.
  2. Transform. Each value is multiplied by 2.
  3. Shape. Keys apple, milk, bread are unchanged.
  4. Safe. prices itself is not modified.

Example 3 — Use Value and Key Together

The iteratee also receives the property name.

Underscore
_.mapObject({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. Build label. Join key and value with ":".
  3. Write back. New strings become the values under the same keys.
  4. Use case. Handy for labels, paths, or keyed messages.

Example 4 — _.mapObject vs _.map

_.map returns an array; _.mapObject keeps the object shape.

Underscore
var obj = {start: 5, end: 12};

_.mapObject(obj, function (v) { return v + 5; });
// → {start: 10, end: 17}

_.map(obj, function (v) { return v + 5; });
// → [10, 17]   // keys dropped
Try It Yourself

How It Works

  1. Same transform. Both add 5 to each value.
  2. mapObject. Returns an object — keys preserved.
  3. map. Returns an array of results — see _.map.
  4. Rule of thumb. Need keys afterward? Prefer _.mapObject.

Browser & Runtime Support

_.mapObject ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore. There is no single native Object.map; this helper fills that gap.

✓ Stable · Underscore 1.x

_.mapObject()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
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
_.mapObject Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API by itself — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.mapObject(object, iteratee) runs the iteratee on each own enumerable value and returns a new object with the same keys and the transformed values. Official example: _.mapObject({start: 5, end: 12}, function (val) { return val + 5; }) returns {start: 10, end: 17}.
For each property, the iteratee is called as (value, key, object) — current value, its key, and the source object. An optional context can bind this.
_.map always returns an array, so mapping an object drops the keys. _.mapObject keeps the keys and returns a new object with the same shape.
No. It builds and returns a new object. The source stays unchanged.
Yes. A string iteratee acts like _.property: _.mapObject(obj, 'name') maps each value to value.name.
No. It is a stable Underscore object helper. Load Underscore 1.x (CDN or npm) and call _.mapObject(object, iteratee).

Next: _.pairs()

Turn an object into an array of [key, value] pairs.

_.pairs() 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