Lodash _.tail() method
What you’ll learn
- How
_.tail(array)yields every element except index0. - Why empty and single-element inputs collapse to
[]. - How tail compares with _.slice(), _.drop(), and _.initial().
- Try each example in the editor (
?tryit=1,2,3) with Lodash from a CDN.
Prerequisites
_.head() grabs the first element—tail intentionally mirrors it by returning the complementary suffix.
- You understand shallow copies: nested objects inside the tail still alias the originals.
- You can open Try-it labs or run snippets locally.
Overview
_.tail trims exactly one leading slot—ideal for recursive walks, queue drains, or stripping command tokens while leaving operands intact.
Drop the head
Always skips index zero—no numeric arity to remember unlike configurable drops.
Array-like friendly
Collections exposing numeric keys plus length coerce just like other Lodash slice helpers.
Non-destructive
Original ordering and references remain untouched for downstream observers.
Syntax
_.tail(array) - array: dense collection or array-like value.
- Returns: new array containing elements from index
1throughlength - 1.
Everything after the first
The leading element disappears while interior order stays unchanged.
import tail from "lodash/tail";
tail(["north", "east", "south", "west"]);
// → ["east", "south", "west"] Empty or singleton
No trailing segment exists once the collection has zero or one slot.
import tail from "lodash/tail";
tail([]);
tail([42]);
// both → [] Array-like object
Numeric indices plus length behave like arguments snapshots without manually spreading.
import tail from "lodash/tail";
const like = { 0: "a", 1: "b", 2: "c", length: 3 };
tail(like);
// → ["b", "c"] 📋 _.tail vs _.slice, _.drop, _.initial
| API | What it removes | Mental model |
|---|---|---|
_.tail(array) | First element only | Suffix starting at index 1 |
_.slice(array, 1) | Everything before index 1 | General window—tail is the readable preset |
_.drop(array, n) | First n elements | Use n = 1 to mirror tail |
_.initial(array) | Last element | Opposite edge—prefix instead of suffix |
Pitfalls to avoid
Shallow tail
Nested structures inside tail slots refer to the same objects as the parent collection.
Expecting undefined
Unlike head, tail never returns undefined—it returns [] when nothing follows.
Confusion with initial
initial trims the final element; combine carefully when piping both ends.
❓ FAQ
Summary
- Purpose:
_.tail(array)returns all elements except the first without mutating the source. - Pairs with: _.head() for destructuring-style splits and _.slice() when windows start elsewhere.
- Next: Lodash _.take(), _.sortedUniqBy() (previous), or the array methods hub.
_.tail is the list “cdr” to _.head()’s “car”: split once, process the leader, then recurse or pipe the remainder through _.drop()-friendly pipelines.
6 people found this page helpful
