Lodash _.rest() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.rest packs trailing call arguments into one array.
  • Why the default start tracks func.length - 1.
  • When lodash helps versus native rest parameters or arguments.
  • Pitfalls around arity hints, default params, and manual start offsets.

Prerequisites

See _.rearg(), _.partial(), and the Function hub.

  • Variadic intuition: functions that accept “the rest” after fixed headers.
  • Function.length: how engines count declared parameters (legacy arity).

Overview

_.rest(func, [start]) wraps func so arguments from start onward collapse into a single array argument—classic lodash sugar before rest parameters were ubiquitous.

Syntax

javascript
_.rest(func, [start])
  • func: target whose trailing args should bundle.
  • start: optional index where grouping begins (defaults to func.length - 1).
  • returns: wrapped invoker producing the grouped call.
1

Default rest on the final parameter

With arity two, lodash defaults start to 1, so every argument after the prefix becomes an array.

javascript
import rest from "lodash/rest";

const greetMany = rest(function (prefix, names) {
  return prefix + ": " + names.join(", ");
});

greetMany("Team", "Ada", "Grace", "Alan");
// "Team: Ada, Grace, Alan"
2

Custom start index

Pass start = 2 when two leading scalars stay separate and everything else forms a tag bucket.

javascript
import rest from "lodash/rest";

const labelSku = rest(function (brand, sku, tags) {
  return brand + "/" + sku + " [" + tags.join("|") + "]";
}, 2);

labelSku("ACME", "404", "sale", "featured", "new");
// "ACME/404 [sale|featured|new]"
3

Head value plus numeric tail

Fold extras after the first argument—handy for CLI-style parsers.

javascript
import rest from "lodash/rest";

const sumHeadTail = rest(function (head, nums) {
  return head + nums.reduce((acc, n) => acc + n, 0);
});

sumHeadTail(100, 1, 2, 3); // 106

📋 _.rest vs native rest params vs arguments

ApproachStrengthTrade-off
_.restRetrofits existing callbacks without editsAnother wrapper layer
Native ...restZero-cost idiomatic ES2015+Requires changing the source signature
arguments slicingWorks in legacy ES5Verbose and easy to mishandle strict mode edge cases

Pitfalls to avoid

Arity

func.length surprises

Default parameters and destructuring can report smaller lengths—set start explicitly when metadata lies.

Arrays

Passing one array argument

rest groups discrete invocation arguments; it does not auto-expand an array you passed as a single value unless you pair with spread.

Composition

Double wrapping

Layering rest, partial, and bind changes arity math—test merged wrappers with realistic call shapes.

❓ FAQ

A wrapper that calls func after grouping arguments from index start onward into one array argument—the usual destination is the final formal parameter.
Lodash defaults start to func.length - 1 so the last declared parameter collects everything after the preceding fixed slots.
Native rest syntax lives in the function declaration. _.rest adapts existing functions or APIs at runtime without rewriting signatures.
The wrapper forwards the invocation context to func like a normal call unless you compose further with bind.
Use import rest from "lodash/rest" so bundlers tree-shake unused Lodash.

Summary

Did you know?

Lodash picks up invocation arguments starting at start (default func.length - 1) and forwards them as a single trailing array—mirroring ES2015 rest parameters for engines or signatures that predate native syntax.

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.

6 people found this page helpful