Lodash _.invokeMap() method

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

What you’ll learn

  • How _.invokeMap(collection, path, ...args) batches host-method calls across a collection.
  • Forwarding trailing arguments identically to every element.
  • When map, manual call/apply, or invoke for a single element fits better.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Skim _.includes() for membership checks and _.flatMap() when mapping needs flattening—not dispatch.

  • You know methods live on prototypes (split, slice) or as own properties on plain objects.
  • You can open Try-it labs or run snippets locally.

Overview

_.invokeMap removes repetitive collection.map((item) => item.doThing(arg)) boilerplate—especially when doThing already exists as a named path.

Uniform dispatch

Same method name or path executed element-by-element.

Shared arguments

Extra parameters replicate across every call automatically.

Function paths

Pass a function to run with each element bound as this.

Syntax

javascript
_.invokeMap(collection, path, [args])
  • collection: array or plain object Lodash can iterate.
  • path: method name string, property path, or function invoked per element.
  • args (optional): forwarded to every invocation after path resolves.
  • Returns: new array of results (same length/order as visitation).
1

String split with a delimiter argument

Strings expose split; Lodash passes "-" to each host string.

javascript
import invokeMap from "lodash/invokeMap";

invokeMap(["a-b-c", "d-e"], "split", "-");
// → [["a", "b", "c"], ["d", "e"]]
Try it Yourself
2

Array slice from index 1

Each inner array receives slice(1)—non-mutating trimming.

javascript
import invokeMap from "lodash/invokeMap";

invokeMap(
  [
    [1, 2, 3],
    [4, 5]
  ],
  "slice",
  1
);
// → [[2, 3], [5]]
Try it Yourself
3

Plain objects with their own methods

Lodash invokes double with each object as this—handy for lightweight domain rows.

javascript
import invokeMap from "lodash/invokeMap";

invokeMap(
  [
    {
      n: 2,
      double() {
        return this.n * 2;
      }
    },
    {
      n: 3,
      double() {
        return this.n * 2;
      }
    }
  ],
  "double"
);
// → [4, 6]
Try it Yourself

📋 _.invokeMap vs map, invoke

APIScopeBest when
_.invokeMap(collection, path, ...args)Every elementBatch host calls with identical arguments
_.map(collection, iteratee)Every elementCustom projections—logic not stored as a path
_.invoke(object, path, ...args)Single objectOne-shot dispatch without mapping

Pitfalls to avoid

Mutation

In-place methods

sort, reverse, splice mutate—clone first when isolation matters.

Binding

Detached functions

Methods ripped off objects lose this—invokeMap intentionally resolves paths on each element.

Perf

Heavy paths

Deep property lookups per row add cost—flatten shapes before hot loops when profiling shows pain.

❓ FAQ

The helper builds a fresh results array, but mutating methods (such as Array.prototype.sort) still alter in-place whatever arrays they touch.
Lodash typically yields undefined for that slot—guard risky lookups before dispatching.
map accepts any iteratee function you write; invokeMap standardizes “call this path or function per element” without spelling apply/bind yourself.
Yes—Lodash accepts property paths like "a.b" or ["a","b"] depending on your schema.
Yes—Lodash invokes it with each element as this and spreads your trailing args.

Summary

Did you know?

Arguments after path are forwarded to every invocation—the same trailing parameters reused across the whole collection. If path is itself a function, Lodash calls it with each element bound as this.

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