Lodash _.map() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.map(collection, iteratee) projects each element into a new array.
  • Using shorthand iteratees ("prop", paths) versus callbacks.
  • Why object collections still yield arrays—and what to use instead for keyed outputs.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Comfort with native Array.prototype.map helps—Lodash extends the same mental model to plain-object collections and iteratee sugar.

  • You understand arrays vs plain objects as key/value maps.
  • You can open Try-it labs or run snippets locally.

Overview

_.map is the backbone of declarative data pipelines—normalize rows, extract columns, or reshape primitives before filtering or reducing downstream.

Parallel outputs

Every visit yields one mapped slot—length mirrors visitation order.

Iteratee sugar

Property strings and matchers skip boilerplate lambdas.

Chain friendly

Pairs cleanly with Lodash sequences and functional pipelines.

Syntax

javascript
_.map(collection, iteratee)
  • collection: array, array-like, or plain object Lodash can iterate.
  • iteratee: invoked as (value, index|key, collection); result becomes the mapped slot.
  • Returns: new array (never reuses the collection container).
1

Transform numbers with a callback

Classic projection—double each entry without imperative loops.

javascript
import map from "lodash/map";

map([1, 2, 3], (n) => n * 2);
// → [2, 4, 6]
Try it Yourself
2

Shorthand: pluck label

Passing a string iteratee pulls that property from each object.

javascript
import map from "lodash/map";

map(
  [
    { id: 1, label: "draft" },
    { id: 2, label: "published" }
  ],
  "label"
);
// → ["draft", "published"]
Try it Yourself
3

Walk a plain object

Iteratee receives (value, key)—the outcome is still an array aligned with visitation.

javascript
import map from "lodash/map";

map({ x: 2, y: 3 }, (value, key) => `${key}:${value}`);
// → ["x:2", "y:3"]
Try it Yourself

📋 _.map vs mapValues, flatMap, forEach

APIOutput shapeBest when
_.map(collection, iteratee)ArrayList projections or object scans needing arrays
_.mapValues(object, iteratee)ObjectPreserve keys while transforming values
_.flatMap(collection, iteratee)Array (flattened)Iteratees return nested arrays to merge one level
_.forEach(collection, iteratee)undefined / chaining side effectsFire-and-forget side effects without collecting results

Pitfalls to avoid

Objects

Expecting keyed output

Switch to mapValues or zipObject when downstream wants the original keys retained.

Mutation

In-place edits inside iteratees

map encourages purity—mutating shared references surprises consumers.

Perf

Extra passes

Chained maps allocate intermediates—fuse logic or profile before micro-tuning native loops.

❓ FAQ

Lodash returns a new array of mapped outputs—it does not replace your collection wholesale—but your iteratee can mutate nested structures if you let it.
_.map standardizes on arrays so chaining stays predictable—pair mapValues when preserving object shape.
flatMap concatenates one level after mapping—use it when iteratees emit nested arrays you intend to merge.
Yes—property names, matcher objects, and path arrays follow Lodash iteratee conventions.
For arrays yes; for plain objects it equals the number of iterated enumerable string-keyed entries.

Summary

  • Purpose: _.map(collection, iteratee) transforms each visited element into a new array.
  • Contrast: pair flatMap when outputs nest; prefer mapValues when keys must survive.
  • Next: Lodash _.orderBy(), Lodash _.keyBy() (previous), or collection hub.
Did you know?

Mapping over a plain object still yields an array of results—one slot per enumerable entry. When you need the same keys back with transformed values, reach for _.mapValues (or build your own reducer).

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.

6 people found this page helpful