Lodash _.map() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Creates a new array by running each element of a collection through an iteratee. Works on arrays and plain objects (object iteration order is not guaranteed). The iteratee receives (value, index|key, collection). Part of Lodash 4.x Collection.

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

Syntax

Call _.map on a collection. Start with this line.

Lodash
_.map(collection, [iteratee=_.identity])
CallWhat it does
_.map(collection, [iteratee=_.identity])Primary signature.
_.map(collection)Call with a collection argument.

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

Library declarations
Lodash
_.map(collection, [iteratee=_.identity])

Parameters

ParameterDescription
collectionRequired. Array or object to iterate
iterateeOptional. Transform; default _.identity

Return Value

Return ValueDescription
*New array of mapped values

Lodash Examples

Example 1 — Official: Square Numbers

Map each array value through a function.

Lodash
function square(n) {
  return n * n;
}

_.map([4, 8], square);
// → [16, 64]
Try It Yourself

How It Works

  1. Visit. Lodash walks each array element.
  2. Call. square(4) then square(8).
  3. Collect. Results fill a new array [16, 64].
  4. No mutate. The original [4, 8] stays the same.

Example 2 — Official: Map Object Values

Plain objects are mapped to an array of results.

Lodash
function square(n) {
  return n * n;
}

_.map({ a: 4, b: 8 }, square);
// → [16, 64]
// iteration order is not guaranteed
Try It Yourself

How It Works

  1. Values. Lodash iterates enumerable values 4 and 8.
  2. Transform. Each is squared.
  3. Shape. Output is an array — keys a / b are not kept.
  4. Need keys? Use _.mapValues.

Example 3 — Official: Property Shorthand

Pass a property name to pluck that field from each object.

Lodash
var users = [
  { user: "barney" },
  { user: "fred" }
];

_.map(users, "user");
// → ["barney", "fred"]
Try It Yourself

How It Works

  1. Shorthand. "user" becomes a property iteratee.
  2. Pluck. Each object’s user field is read.
  3. Result. Names land in a new string array.
  4. vs map. Same idea as users.map(u => u.user).

Example 4 — Double Each Number

Simple numeric projection with an inline function.

Lodash
_.map([1, 2, 3], function (n) {
  return n * 2;
});
// → [2, 4, 6]
Try It Yourself

How It Works

  1. Input. Three numbers in order.
  2. Rule. Multiply each by 2.
  3. Output. [2, 4, 6] — same length, new values.
  4. Length. Array maps keep a 1:1 slot mapping.

Example 5 — Use Index in the Iteratee

The second argument is the index (or object key).

Lodash
_.map(["a", "b", "c"], function (value, index) {
  return value + index;
});
// → ["a0", "b1", "c2"]
Try It Yourself

How It Works

  1. Args. Iteratee gets (value, index, collection).
  2. Combine. Concatenate letter + index.
  3. Collect. Three labeled strings form the result.
  4. Objects. On plain objects, the second arg is the key name.

Browser & Runtime Support

_.map is a Lodash 4.x Collection helper. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.prototype.map covers arrays only.

✓ Stable · Lodash 4.x

_.map()

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

100% With Lodash 4.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 Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import map from "lodash/map" for smaller builds. Use native Array.map for array-only modern code.

Frequently Asked Questions

_.map(collection, iteratee) runs each element through iteratee and returns a new array of results.
No. It returns a new array. Your iteratee can still mutate nested objects if you change them.
_.map always returns an array. To keep object keys with new values, use _.mapValues.
flatMap maps then flattens one level — use it when each iteratee returns an array you want to merge.
Yes. Pass a string like "user" as the iteratee shorthand to pluck that property.
(value, index|key, collection) — three arguments, like Array.prototype.map.

Next: _.orderBy()

Sort a collection by one or more iteratees with asc/desc orders.

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

9 people found this page helpful