Lodash _.methodOf() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

The opposite of _.method: creates a function that invokes the method at a given path on a fixed object. Extra arguments are forwarded to that method. Part of Lodash Util since 3.7.0 (stable — not deprecated).

Note: The object is fixed; the path is supplied later — ideal for _.map over a list of paths against one target.

Syntax

Call _.methodOf. Start with this line.

Lodash
_.methodOf(object, [args])
CallWhat it does
_.methodOf(object, [args])Primary signature.
_.methodOf(...)Call the util helper.

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

Library declarations
Lodash
_.methodOf(object, [args])

Parameters

ParameterDescription
objectRequired. Object whose methods will be invoked
argsOptional. Arguments forwarded to each method

Return Value

Return ValueDescription
*Invoker (path) → result

Lodash Examples

Example 1 — Official: Map String Paths

Invoke several paths on one shared object.

Lodash
var array = _.times(3, _.constant),
    object = { 'a': array, 'b': array, 'c': array };

_.map(['a[2]', 'c[0]'], _.methodOf(object));
// → [2, 0]
Try It Yourself

How It Works

  1. Array of fns. _.times(3, _.constant) builds getters for 0, 1, 2.
  2. Shared object. Keys a, b, c all point at that array.
  3. Invoker. _.methodOf(object) fixes the object; paths arrive later.
  4. Map. 'a[2]' → 2, 'c[0]' → 0.

Example 2 — Official: Path Arrays

Same results with array paths instead of bracket strings.

Lodash
var array = _.times(3, _.constant),
    object = { 'a': array, 'b': array, 'c': array };

_.map([['a', '2'], ['c', '0']], _.methodOf(object));
// → [2, 0]
Try It Yourself

How It Works

  1. Array path. ['a', '2'] resolves like 'a[2]'.
  2. Same invoker. Still calls the function at that path on object.
  3. Result. Identical output: [2, 0].
  4. Pick a style. Arrays help when keys are dynamic or numeric.

Example 3 — Bound Method Arguments

Arguments after object are passed into every invoked method.

Lodash
var calc = {
  add: function (a, b) { return a + b; },
  mul: function (a, b) { return a * b; }
};

var run = _.methodOf(calc, 10, 5);

run('add');
// → 15

run('mul');
// → 50
Try It Yourself

How It Works

  1. Fix object + args. calc, 10, and 5 are bound up front.
  2. Vary path. run('add') → calc.add(10, 5).
  3. Same args. run('mul') → calc.mul(10, 5).
  4. Dispatch. Classic object-first, path-later pattern.

Example 4 — Call the Invoker Directly

You do not need _.map — pass one path to the returned function.

Lodash
var array = _.times(3, _.constant),
    object = { 'a': array, 'c': array };

var invoke = _.methodOf(object);
invoke('a[2]');
// → 2

_.invoke(object, 'c[0]');
// → 0  // one-shot form
Try It Yourself

How It Works

  1. Factory. Build an invoker once with _.methodOf.
  2. Call. Pass a single path → method runs on the fixed object.
  3. Compare. _.invoke is the one-shot equivalent.
  4. Choose. Many paths → methodOf; one call → invoke.

Example 5 — methodOf vs method

Same call, opposite binding order.

Lodash
var array = _.times(3, _.constant),
    object = { 'a': array };

_.methodOf(object)('a[2]');
// → 2

_.method('a[2]')(object);
// → 2  // same result, path fixed first
Try It Yourself

How It Works

  1. methodOf. Object first → pass path later.
  2. method. Path first → pass object later.
  3. Same call. Both invoke object.a[2]() → 2.
  4. Rule. Many paths / one object → methodOf; many objects / one path → method.

Browser & Runtime Support

_.methodOf is a Lodash Util helper since 3.7.0. It runs anywhere Lodash 3.7+ / 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.7.0+

_.methodOf()

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

100% With Lodash 3.7+
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
_.methodOf Lodash 3.7.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import methodOf from "lodash/methodOf" for smaller bundles. Pair with _.map when you have many paths on one object.

Frequently Asked Questions

_.methodOf(object, …args) returns a function that takes a path and invokes the method at that path on the fixed object, forwarding any args you bound when creating the invoker. It is the opposite of _.method.
A path (string or array)—not the object. Example: _.methodOf(object)('a[2]') calls the method at object.a[2].
Arguments after object in _.methodOf are bound at create time. Example: _.methodOf(calc, 10, 5)('add') calls calc.add(10, 5).
_.method(path) fixes the path—the object comes later. _.methodOf(object) fixes the object—the path comes later. Mirror-image invoker factories.
No. That treats 'greet' as a method argument, not a path. Use _.methodOf(object)('greet') or _.method('greet')(object).
Use it when one object exposes several methods and you pick the path at runtime—dispatch tables, registries, or mapping a list of paths against a fixed target.

Next: _.mixin()

Extend Lodash with your own methods that support chaining and iteratee shorthands.

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