Lodash _.rearg() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Creates a function that invokes func with arguments rearranged by an index map. The value at the first listed index becomes the first argument to func, and so on. Part of Lodash 4.x Function (since 3.0.0).

Pass the required arguments shown below. Most helpers return a new function you call later.

Syntax

Call _.rearg. Start with this line.

Lodash
_.rearg(func, indexes)
CallWhat it does
_.rearg(func, indexes)Primary signature.
_.rearg(func)Wrap or transform a function.

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

Library declarations
Lodash
_.rearg(func, indexes)

Parameters

ParameterDescription
funcRequired. Function to wrap
indexesRequired. Arrangement of argument indexes

Return Value

Return ValueDescription
*New rearranged function

Lodash Examples

Example 1 — Official: Index Map [2, 0, 1]

Pull call-site args in a custom order into the wrapped function.

Lodash
var rearged = _.rearg(function(a, b, c) {
  return [a, b, c];
}, [2, 0, 1]);

rearged("b", "c", "a");
// → ["a", "b", "c"]
Try It Yourself

How It Works

  1. Call. Wrapper receives ("b", "c", "a").
  2. Map. [2, 0, 1] → take indexes 2, then 0, then 1.
  3. Pass. Original function sees ("a", "b", "c").
  4. Return. ["a", "b", "c"].

Example 2 — Swap Two Arguments

A two-slot swap is the simplest useful rearrange.

Lodash
function greet(greeting, name) {
  return greeting + " " + name;
}

var greetSwapped = _.rearg(greet, [1, 0]);
greetSwapped("Ada", "Hello");
// → "Hello Ada"
Try It Yourself

How It Works

  1. Call. ("Ada", "Hello") — name first at the call site.
  2. Map. [1, 0] swaps the two slots.
  3. Run. greet("Hello", "Ada").
  4. Use. Adapt APIs that pass arguments in the “wrong” order.

Example 3 — Indexes as Rest Numbers

You can pass indexes without wrapping them in an array.

Lodash
var rearged = _.rearg(function(a, b, c) {
  return [a, b, c];
}, 2, 0, 1);

rearged("b", "c", "a");
// → ["a", "b", "c"]
Try It Yourself

How It Works

  1. Signature. Docs allow ...(number|number[]).
  2. Same map. 2, 0, 1 matches [2, 0, 1].
  3. Result. Identical to the official array form.
  4. Style. Prefer one form in a codebase for consistency.

Example 4 — Rotate Left

Move every argument one slot toward the front.

Lodash
var rotated = _.rearg(function(a, b, c) {
  return [a, b, c];
}, [1, 2, 0]);

rotated("x", "y", "z");
// → ["y", "z", "x"]
Try It Yourself

How It Works

  1. Map. [1, 2, 0] → take 2nd, 3rd, then 1st call-site args.
  2. Call. ("x", "y", "z").
  3. Pass. Function receives ("y", "z", "x").
  4. Pattern. Rotations and custom maps are why rearg beats a hard-coded reverse.

Example 5 — _.rearg vs _.flip

Full reverse is a special case; rearg can do more.

Lodash
function triple(a, b, c) {
  return [a, b, c];
}

_.flip(triple)(1, 2, 3);
// → [3, 2, 1]

_.rearg(triple, [2, 1, 0])(1, 2, 3);
// → [3, 2, 1]  (same reverse)

_.rearg(triple, [2, 0, 1])(1, 2, 3);
// → [3, 1, 2]  (not a simple reverse)
Try It Yourself

How It Works

  1. Flip. Always reverses the full argument list.
  2. Rearg reverse. [2, 1, 0] matches that reverse for three args.
  3. Custom. [2, 0, 1] is a different permutation.
  4. Pick. Use flip for reverse-only; use rearg for any map.

Browser & Runtime Support

_.rearg is a Lodash 4.x Function helper (added in 3.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.0.0+

_.rearg()

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

100% With Lodash 3.0.0+
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
_.rearg Lodash 3.0.0+

Bottom line: Safe for production once Lodash 3.0.0+ is on the page or in your bundle. Prefer import rearg from "lodash/rearg" for smaller builds. For a full reverse, use _.flip.

Frequently Asked Questions

_.rearg(func, indexes) returns a new function that rearranges the arguments it receives according to indexes, then calls func. The value at indexes[0] becomes the first argument to func, indexes[1] the second, and so on.
Destination order: the nth parameter passed to func is args[indexes[n]] from the wrapper call. Example: [2, 0, 1] means func(args[2], args[0], args[1]).
_.flip reverses all arguments. _.rearg accepts any permutation — swaps, rotations, or picking a subset of slots.
Yes. Lodash accepts indexes as ...(number|number[]) — either _.rearg(fn, [2, 0, 1]) or _.rearg(fn, 2, 0, 1).
No. It returns a new wrapper. The original function is unchanged.
Use import rearg from "lodash/rearg" or require("lodash/rearg") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.rearg.

Next: _.rest()

Create a function that collects arguments from a start index into an array — Lodash’s rest-parameter helper.

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