Lodash _.dropRight() method

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

What you’ll learn

  • How _.dropRight(array, n) returns a new array without the last n entries.
  • Defaults for n, and edge cases for 0, empty arrays, and n beyond the length.
  • How dropRight pairs with _.drop, _.initial, and native slice.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.drop() first; optional familiarity with array.slice(0, -1) in native JavaScript.

  • You know that negative end indexes in slice count from the end of the array.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.dropRight answers “give me the list without the last n items.” It mirrors _.drop but trims from the end, keeping leading order intact—ideal for stripping footers, closing tokens, or trailing blanks.

Non-destructive

The source array stays the same; you always receive a new array instance.

Trim suffixes

Drop trailing sentinels, checksum fields, or duplicate closing markers after parsing.

Pairs with initial

_.initial is the fixed “drop one from the right” spelling; dropRight generalizes the count.

Syntax

javascript
_.dropRight(array, [n=1])
  • array: source collection (array-like values are coerced).
  • n: non-negative integer count of elements to remove from the end; defaults to 1 when omitted.
  • Returns: a new array of the remaining leading elements in original order.
1

Default: drop one from the end

With only the array argument, Lodash removes the last element and returns the leading slice.

javascript
import dropRight from "lodash/dropRight";

dropRight([1, 2, 3]);
// [1, 2]
Try it Yourself
2

Drop several from the right

Pass n to strip multiple trailing values in one call.

javascript
import dropRight from "lodash/dropRight";

dropRight([1, 2, 3], 2);
// [1]
Try it Yourself
3

Zero and “drop everything”

n = 0 keeps the whole sequence (new array). If n is at least the length, the result is empty.

javascript
import dropRight from "lodash/dropRight";

dropRight([1, 2, 3], 0);
// [1, 2, 3]

dropRight([1, 2, 3], 5);
// []
Try it Yourself

📋 _.dropRight vs _.drop vs initial

APIWhat it doesNote
_.dropRight(arr, n)New array without last n itemsDefault n is 1
_.drop(arr, n)New array without first n itemsSymmetric trim from the opposite side
_.initial(arr)Drop exactly one from the endSame as _.dropRight(arr) for ordinary arrays

Pitfalls to avoid

Sharing

Shallow copy only

Elements are not cloned; removed positions still exist on the original array if you keep a reference to it.

Start

Trimming from the left

dropRight never removes leading items. For that, use _.drop or slice with a positive start index.

Mutate

Need in-place pop

pop and splice mutate the source. dropRight is for immutable-style pipelines.

❓ FAQ

No. Lodash returns a new array; the source array is unchanged.
When n is undefined or omitted, Lodash removes one element from the end—the common “all but last” case.
You get an empty array. Lodash does not throw.
After normalization, 0 means drop nothing from the right: you receive a new array containing every element (shallow copy semantics).
Use import dropRight from "lodash/dropRight" or require("lodash/dropRight") for tree-shaking friendly bundles.

Summary

Did you know?

With the default n = 1, _.dropRight matches _.initial for ordinary arrays: both return all elements except the last, as a new array.

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