Underscore.js _.rest() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Array

Definition

Returns the rest of the elements in an array. Pass an index to return values from that index onward (official Underscore docs). Aliases: tail, drop. Stable — not deprecated.

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

Syntax

Call _.rest. Start with this line.

Underscore
_.rest(array, [index])
CallWhat it does
_.rest(array, [index])Primary signature.
_.rest(...)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
_.rest(array, [index])

Parameters

ParameterDescription
arrayRequired. Source list
indexOptional. Start position (default 1)

Return Value

Return ValueDescription
*New array from that index onward

Underscore.js Examples

Example 1 — Official: Drop the First

Omit the index — Underscore starts at position 1.

Underscore
_.rest([5, 4, 3, 2, 1]);
// → [4, 3, 2, 1]
Try It Yourself

How It Works

  1. Source. Five numbers; indexes 0 … 4.
  2. Default index. Missing second arg → start at 1.
  3. Keep the tail. Copy from 4 through 1.
  4. New array. The original list is unchanged.

Example 2 — Start From an Index

Pass an index to return values from that position onward.

Underscore
_.rest([5, 4, 3, 2, 1], 2);
// → [3, 2, 1]
Try It Yourself

How It Works

  1. Index 2. Skip slots 0 and 1 (5 and 4).
  2. Copy onward. Keep 3, 2, and 1.
  3. Same idea as slice. Equivalent to [5,4,3,2,1].slice(2).
  4. Use case. Skip a header, peel a queue head of size n, or page into a list.

Example 3 — _.tail and _.drop

Aliases behave identically — choose the clearer name.

Underscore
var letters = ["a", "b", "c", "d"];

_.tail(letters);      // → ["b", "c", "d"]
_.drop(letters, 2);   // → ["c", "d"]
Try It Yourself

How It Works

  1. Same function. _.tail and _.drop point at _.rest.
  2. tail. Reads like “everything after the head.”
  3. drop(n). Reads like “remove the first n items.”
  4. Style. Pick one alias per codebase for consistency.

Example 4 — _.rest vs _.initial

Rest trims the front; initial trims the end.

Underscore
var nums = [1, 2, 3, 4, 5];

_.rest(nums);     // → [2, 3, 4, 5]
_.initial(nums);  // → [1, 2, 3, 4]
Try It Yourself

How It Works

  1. rest. Drops 1 from the front → keeps the tail.
  2. initial. Drops 5 from the end → keeps the front.
  3. Pick by intent. Skip a header? Use rest. Drop a trailer? Use initial.
  4. Pair with ends. _.first / _.last for single ends.

Browser & Runtime Support

_.rest (and aliases _.tail / _.drop) 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

_.rest()

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
_.rest 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]). Native equivalent: array.slice(index).

Frequently Asked Questions

_.rest(array) returns a new array with everything except the first element. Pass an index as _.rest(array, index) to return values from that index onward.
_.tail and _.drop are aliases of _.rest — they behave identically. Use whichever name reads best.
It is the start position in the array (like Array.prototype.slice). Omit it and Underscore starts at index 1 — dropping just the first element.
An empty array []. Dropping past the end also returns [], never an error.
_.rest drops from the front and keeps the tail. _.initial drops from the end and keeps the front.
No. It returns a new array; the source is left unchanged.

Next: _.compact()

Remove all falsy values from an array in one clear call.

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