Lodash _.rest() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Creates a function that invokes func with arguments from start and beyond provided as an array. Based on the rest parameter. Part of Lodash 4.x Function (since 4.0.0; Lodash 3 named this _.restParam).

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

Syntax

Call _.rest. Start with this line.

Lodash
_.rest(func, [start=func.length-1])
CallWhat it does
_.rest(func, [start=func.length-1])Primary signature.
_.rest(func)Wrap or transform a function.

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

Library declarations
Lodash
_.rest(func, [start=func.length-1])

Parameters

ParameterDescription
funcRequired. Function that accepts a trailing array
startOptional. Index where collection begins; default func.length - 1

Return Value

Return ValueDescription
*New rest-style wrapper

Lodash Examples

Example 1 — Official: Greeting + Names

First argument stays alone; the rest become a names array.

Lodash
var say = _.rest(function(what, names) {
  return what + " " + _.initial(names).join(", ") +
    (_.size(names) > 1 ? ", & " : "") + _.last(names);
});

say("hello", "fred", "barney", "pebbles");
// → "hello fred, barney, & pebbles"
Try It Yourself

How It Works

  1. Arity. Inner function length is 2 → default start = 1.
  2. Split. "hello" is what; the names fill the array.
  3. Format. _.initial + join, then _.last with &.
  4. Result. A readable “hello A, B, & C” string.

Example 2 — Sum Trailing Numbers

A fixed label, then any number of values to total.

Lodash
var taggedSum = _.rest(function(label, nums) {
  var total = 0;
  for (var i = 0; i < nums.length; i++) total += nums[i];
  return label + ": " + total;
});

taggedSum("score", 10, 20, 5);
// → "score: 35"
Try It Yourself

How It Works

  1. Fixed. First argument is the label string.
  2. Rest. 10, 20, 5 become nums.
  3. Loop. Sum the array to 35.
  4. Use. Logging helpers, scoreboards, or CSV-style builders.

Example 3 — Custom start = 0

Collect every argument into a single array.

Lodash
var asList = _.rest(function(items) {
  return items;
}, 0);

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

How It Works

  1. start 0. Collection begins at the first argument.
  2. No head. There are no leading fixed scalars.
  3. One param. Inner items receives the full list.
  4. Tip. Raise start when more leading slots should stay separate.

Example 4 — Empty Rest Array

If nothing follows the fixed args, the collected array is empty.

Lodash
var describe = _.rest(function(title, items) {
  return title + " → " + JSON.stringify(items);
});

describe("pack");
// → 'pack → []'
Try It Yourself

How It Works

  1. Only title. One argument at the call site.
  2. Rest. Nothing left after start → [].
  3. Safe. No throw — check items.length if needed.
  4. Same as native. function (a, ...r) also gets [] when omitted.

Example 5 — _.rest vs _.spread

Opposite directions: gather args vs expand an array.

Lodash
var gather = _.rest(function(head, tail) {
  return { head: head, tail: tail };
});

gather("a", "b", "c");
// → { head: "a", tail: ["b", "c"] }

var expand = _.spread(function(who, what) {
  return who + " says " + what;
});

expand(["fred", "hello"]);
// → "fred says hello"
Try It Yourself

How It Works

  1. Rest. Many call-site values → one array parameter.
  2. Spread. One array value → many parameters.
  3. Pair. Docs model them after rest and spread operators.
  4. Pick. Use rest to accept lists; use spread for Promise/array pipelines.

Browser & Runtime Support

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

✓ Stable · Lodash 4.0.0+

_.rest()

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

100% With Lodash 4.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
_.rest Lodash 4.0.0+

Bottom line: Safe for production once Lodash 4.0.0+ is on the page or in your bundle. Prefer import rest from "lodash/rest" for smaller builds. For expanding arrays into args, use _.spread.

Frequently Asked Questions

_.rest(func, [start=func.length-1]) returns a wrapper that invokes func with arguments from start onward collected into one trailing array argument — like ES rest parameters applied at runtime.
func.length - 1. So the last formal parameter of func typically receives the collected array, and earlier parameters stay as individual values.
Native rest lives in the function declaration. _.rest wraps an existing function so you can add rest-style collection without rewriting its source signature.
_.rest gathers many call-site args into one array for the wrapped function. _.spread does the opposite — expands an array into separate arguments.
The wrapper uses the this binding of the created function when calling func — same idea as a normal method-style call unless you bind further.
Use import rest from "lodash/rest" or require("lodash/rest") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.rest.

Next: _.spread()

Create a function that expands an array into arguments — the counterpart to _.rest.

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