Lodash _.invoke() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Invokes the method at path of object and returns the result. Part of Lodash Object (stable — not deprecated). Extra arguments after path are forwarded to the method. For the same call across a collection, use _.invokeMap.

Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.

Syntax

Call _.invoke. Start with this line.

Lodash
_.invoke(object, path, ...args)
CallWhat it does
_.invoke(object, path, ...args)Primary signature.
_.invoke(object)Work with an object’s keys, values, or paths.

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

Library declarations
Lodash
_.invoke(object, path, ...args)

Parameters

ParameterDescription
objectRequired. Object to query
pathRequired. String or array path to the method
...argsOptional. Arguments forwarded to the method

Return Value

Return ValueDescription
*Result of the invoked method

Lodash Examples

Example 1 — Official: Nested slice

Resolve a deep array and call a method on it.

Lodash
var object = { a: [{ b: { c: [1, 2, 3, 4] } }] };

console.log(_.invoke(object, "a[0].b.c.slice", 1, 3));
// [2, 3]
Try It Yourself

How It Works

  1. Path. Walks to the nested array [1, 2, 3, 4].
  2. Method. Finds slice on that array.
  3. Args. Forwards 1, 3 → slice(1, 3).
  4. Docs. Matches the official Lodash example.

Example 2 — Same Call with an Array Path

Array paths avoid ambiguous dotted keys.

Lodash
var object = { a: [{ b: { c: [1, 2, 3, 4] } }] };

console.log(_.invoke(object, ["a", 0, "b", "c", "slice"], 1, 3));
// [2, 3]
Try It Yourself

How It Works

  1. Segments. ['a', 0, 'b', 'c', 'slice'] mirrors the string path.
  2. Call. Same slice(1, 3) result.
  3. When. Prefer arrays if a key contains dots or brackets.
  4. Same API. Extra args still follow the path.

Example 3 — Pass Arguments to the Method

Any values after path are method arguments.

Lodash
var data = { tags: ["js", "lodash", "node"] };

console.log(_.invoke(data, "tags.join", " | "));
// 'js | lodash | node'

console.log(_.invoke(data, "tags.includes", "lodash"));
// true
Try It Yourself

How It Works

  1. join. Separator " | " is the first method arg.
  2. includes. Search value "lodash" is forwarded.
  3. this. Bound to data.tags for both calls.
  4. Use. Dynamic method names with fixed argument lists.

Example 4 — Missing Path Returns undefined

Safe when the method may not exist.

Lodash
var object = { a: [{ b: { c: [1, 2, 3, 4] } }] };

console.log(_.invoke(object, "a[0].b.c.missing", 1));
// undefined

console.log(_.invoke(object, "nope.slice", 0, 1));
// undefined
Try It Yourself

How It Works

  1. Missing method. Path resolves, but missing is not a function → undefined.
  2. Missing parent. Broken path short-circuits safely.
  3. Contrast. A non-function that does exist can still throw if called.
  4. Tip. Guard dynamic paths with typeof when unsure.

Example 5 — _.invoke vs _.invokeMap

One object vs every item in a collection.

Lodash
var one = { nums: [1, 2, 3, 4] };
var many = [[1, 2, 3, 4], [5, 6, 7, 8]];

console.log(_.invoke(one, "nums.slice", 1, 3));
// [2, 3]

console.log(_.invokeMap(many, "slice", 1, 3));
// [[2, 3], [6, 7]]
Try It Yourself

How It Works

  1. invoke. One nested call on a single object.
  2. invokeMap. Same method on each collection element.
  3. When. Deep path on one object → invoke.
  4. When. Batch calls → invokeMap.

Browser & Runtime Support

_.invoke is a Lodash Object helper available in 4.x. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native equivalents resolve a path then call the function with the correct parent as this.

✓ Stable · Lodash 4.x

_.invoke()

Available in [email protected] full builds and the lodash/invoke 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
_.invoke Lodash 4.x

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import invoke from "lodash/invoke" for smaller builds. Use invokeMap for collection-wide calls.

Frequently Asked Questions

_.invoke(object, path, ...args) invokes the method at path of object and returns the result. Official: _.invoke(object, 'a[0].b.c.slice', 1, 3) → [2, 3].
_.invoke calls one method on one object. _.invokeMap calls the same method on every element of a collection.
Like a normal method call, this is the parent of the method along the path — for example user.profile.toJSON runs with this === user.profile.
A missing method path returns undefined. If the path exists but is not a function, calling it can throw a TypeError — guard dynamic paths when needed.
Yes. String paths like 'a[0].b.c.slice' and array paths like ['a', 0, 'b', 'c', 'slice'] both work.
Use import invoke from "lodash/invoke" or require("lodash/invoke") so bundlers can tree-shake. Full build: import _ from "lodash" then _.invoke.

Next: _.keys()

List an object’s own enumerable property names.

_.keys() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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