Underscore.js _.map() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Collection

Definition

Produces a new array of values by mapping each value in list through a transformation function (iteratee). The iteratee receives (value, index|key, list) (official Underscore docs).

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

Syntax

Call _.map. Start with this line.

Underscore
_.map(list, iteratee, [context])
CallWhat it does
_.map(list, iteratee, [context])Primary signature.
_.map(...)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
_.map(list, iteratee, [context])

Parameters

ParameterDescription
listRequired. Array, array-like, or plain object
iterateeRequired. Function (or property string) that returns the new value
contextOptional. this for the iteratee

Return Value

Return ValueDescription
*New array of transformed values

Underscore.js Examples

Example 1 — Official: Transform Numbers

Return a new value for each item; collect them into an array.

Underscore
_.map([1, 2, 3], function (num) {
  return num * 3;
});
// → [3, 6, 9]
Try It Yourself

How It Works

  1. Iteratee. Receives each number and returns num * 3.
  2. Collect. Returns are gathered into a new array.
  3. Order. Same order as the input.
  4. Safe. Source [1, 2, 3] is unchanged.

Example 2 — Official: Map Object Values

On a plain object, iterate values — still return a flat array.

Underscore
_.map({ one: 1, two: 2, three: 3 }, function (num, key) {
  return num * 3;
});
// → [3, 6, 9]
Try It Yourself

How It Works

  1. Values. Underscore walks each object value (1, 2, 3).
  2. Key arg. Second parameter is the key ("one", "two", …).
  3. Flat array. Keys are not kept in the result — only transformed values.
  4. Same idea. Still “transform each → new array.”

Example 3 — Official: Pass a Function Reference

You can pass an existing function (here _.first) as the iteratee.

Underscore
_.map([[1, 2], [3, 4]], _.first);
// → [1, 3]
Try It Yourself

How It Works

  1. Each row. First item is [1, 2]; second is [3, 4].
  2. _.first. Returns the first element of each nested array.
  3. Result. [1, 3] — one value per row.
  4. Reuse. Any compatible function can be the iteratee.

Example 4 — Property Shorthand

Pass a string to map each object to that property (like a light _.pluck).

Underscore
var people = [
  { name: "Ada", age: 36 },
  { name: "Linus", age: 55 }
];

_.map(people, "name");
// → ["Ada", "Linus"]
Try It Yourself

How It Works

  1. Shorthand. "name" means read each object’s .name.
  2. Collect. Builds ["Ada", "Linus"].
  3. vs pluck. Same idea as _.pluck(people, "name") for this case.
  4. Custom? Need more than one field → use a function iteratee.

Browser & Runtime Support

_.map / _.collect 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.

✓ Stable · Underscore 1.x

_.map()

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
_.map Underscore 1.x+

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

Frequently Asked Questions

_.map(list, iteratee, [context]) produces a new array by transforming each value in list through the iteratee. It works on arrays and plain objects, and always returns an array — the original collection is unchanged.
collect is an alias of map — the same function. Use whichever name your team prefers.
Three arguments: value, then index (or key), then the whole list — (value, index, list) for arrays and (value, key, list) for objects.
_.each runs a callback for side effects and returns the original list. _.map collects each return value into a new array — use it when you need transformed data.
Yes. It iterates the object’s values and still returns a flat array of results — keys are not preserved in the output.
Yes. A string like 'name' acts as a property shorthand — _.map(list, 'name') is like plucking that field from each item.

Next: _.reduce()

Fold a collection into one value — sums, objects, and more.

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