Underscore.js _.invoke() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Collection

Definition

Calls the method named by methodName on each value in the list. Extra arguments are forwarded to every call (official Underscore docs).

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

Syntax

Call _.invoke. Start with this line.

Underscore
_.invoke(list, methodName, *arguments)
CallWhat it does
_.invoke(list, methodName, *arguments)Primary signature.
_.invoke(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.invoke(list, methodName, *arguments)

Parameters

ParameterDescription
listRequired. Collection of values
methodNameRequired. String name of the method (or a function in modern Underscore)
*argumentsOptional. Forwarded to each method call

Return Value

Return ValueDescription
*New array of each call’s result

Underscore.js Examples

Example 1 — Official: Invoke sort

Call the same method name on every item and collect the returns.

Underscore
_.invoke([[5, 1, 7], [3, 2, 1]], "sort");
// → [[1, 5, 7], [1, 2, 3]]
Try It Yourself

How It Works

  1. Method name. "sort" means call .sort() on each value.
  2. First array. [5,1,7] becomes [1,5,7].
  3. Second array. [3,2,1] becomes [1,2,3].
  4. Return. New outer array of those results — and the inners are mutated.

Example 2 — Forward Arguments

Extra args after the method name are passed into every call.

Underscore
_.invoke([1.234, 5.678], "toFixed", 1);
// → ["1.2", "5.7"]
Try It Yourself

How It Works

  1. Method. Each number has toFixed.
  2. Arg. 1 is forwarded → toFixed(1).
  3. Results. New strings "1.2" and "5.7".
  4. No mutate. Numbers are primitives; originals stay unchanged.

Example 3 — String Method

Same pattern works for string methods like toUpperCase.

Underscore
_.invoke(["ada", "linus", "grace"], "toUpperCase");
// → ["ADA", "LINUS", "GRACE"]
Try It Yourself

How It Works

  1. Call. Each string runs .toUpperCase().
  2. Collect. Return values form a new array of uppercase names.
  3. Order. Same order as the input list.
  4. Immutable strings. Source strings are not changed.

Example 4 — _.invoke vs _.map

Same outcome — named method shortcut vs your own function.

Underscore
var words = ["hi", "bye"];

_.invoke(words, "toUpperCase");
// → ["HI", "BYE"]

_.map(words, function (w) {
  return w.toUpperCase();
});
// → ["HI", "BYE"]
Try It Yourself

How It Works

  1. invoke. Pass the method name as a string — shorter for one call.
  2. map. Pass a function — better for custom logic.
  3. Same result. Both return ["HI","BYE"] here.
  4. Pick by intent. Existing method → invoke; custom logic → map.

Browser & Runtime Support

_.invoke ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.invoke()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.invoke(list, methodName, *arguments) calls the named method on every value in the list and returns a new array of the results. Extra arguments are forwarded to each call.
List them after the method name — e.g. _.invoke([1.234, 5.678], 'toFixed', 1) calls toFixed(1) on each number.
_.map runs a function you supply. _.invoke is a shortcut for calling a named method already on each item — roughly map(item => item[methodName](...args)).
_.pluck reads a property. _.invoke calls a method. Use pluck for fields like name; use invoke for methods like toUpperCase or sort.
It returns a new result array. The outer list is not replaced — but the invoked method may mutate items (Array.prototype.sort does).
Calling a missing method throws (e.g. TypeError). Every item should support the method name you pass.

Next: _.pluck()

Extract a single property from every item — the common map use-case.

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

10 people found this page helpful