Lodash _.drop() method
What you’ll learn
- How
_.drop(array, n)returns a new array skipping the firstnentries. - Defaults for
n, plus edge cases for0, empty arrays, andnbeyond the length. - How
dropcompares toslice,tail, anddropRightin the Lodash toolbox. - Try each example in the editor (
?tryit=1,2,3) with Lodash from a CDN.
Prerequisites
Arrays and zero-based indexing; optional prior read _.differenceWith() on this site.
- You know that
array.slice(1)in native JavaScript returns a new array without mutating the source. - You can run snippets in Node or open the Try-it labs in a browser.
Overview
_.drop answers “give me the rest of the list after skipping the first n items.” It is a small, readable helper over slice(n) with Lodash’s usual coercion rules and a default of n = 1 when you only pass the array.
Non-destructive
The source array stays the same; you always work with a new result array.
Skip headers
Useful after parsing CSV rows, log lines, or token lists where the first cells are metadata.
Pairs with tail
_.tail is the fixed “drop one” spelling; drop adds a configurable count.
Syntax
_.drop(array, [n=1]) - array: source collection (array-like values are coerced).
- n: non-negative integer count of elements to remove from the start; defaults to
1when omitted. - Returns: a new array of the remaining elements in original order.
Default: drop one
With only the array argument, Lodash removes the first element and returns the tail.
import drop from "lodash/drop";
drop([1, 2, 3]);
// [2, 3] Drop a specific count
Pass n to skip multiple leading values in one call.
import drop from "lodash/drop";
drop([1, 2, 3], 2);
// [3] Zero and “drop everything”
n = 0 keeps the whole sequence (new array). If n is not smaller than the length, the result is empty.
import drop from "lodash/drop";
drop([1, 2, 3], 0);
// [1, 2, 3]
drop([1, 2, 3], 5);
// [] 📋 _.drop vs slice vs tail
| API | What it does | Note |
|---|---|---|
_.drop(arr, n) | New array without first n items | Default n is 1; reads well in pipelines |
arr.slice(n) | Native slice from index n to the end | Same shape for non-mutating skips; no Lodash coercion helpers |
_.tail(arr) | Drop exactly one element | Equivalent to _.drop(arr) for ordinary arrays |
Pitfalls to avoid
Shallow copy only
Elements are not cloned; objects inside the dropped region still exist in the original array if you keep a reference to it.
Trimming from the right
drop only removes from the start. For suffix removal use _.dropRight or slice with a negative end index.
Need in-place shift
splice, shift, or queue structures mutate the source. drop is for pure pipelines that prefer immutability.
❓ FAQ
Summary
- Purpose:
_.drop(array, n)returns a new array without the firstnelements (defaultn = 1). - Safety: the input array is not mutated.
- Next: Lodash _.dropRight(), _.differenceWith(), or the array methods hub.
Omitting n (or using Lodash’s guarded arity so the second argument is treated as absent) makes Lodash drop one element, the same effect as _.tail on a non-empty array.
6 people found this page helpful
