Lodash _.dropRightWhile() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate returns falsey. Part of Lodash Array since 3.0.0 (stable in 4.x — not deprecated).

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

Syntax

Call _.dropRightWhile on an array. Start with this line.

Lodash
_.dropRightWhile(array, [predicate=_.identity])
CallWhat it does
_.dropRightWhile(array, [predicate=_.identity])Primary signature.
_.dropRightWhile(array)Call with an array argument.

Prefer import dropRightWhile from "lodash/dropRightWhile" when you want a smaller bundle.

Library declarations
Lodash
_.dropRightWhile(array, [predicate=_.identity])

Parameters

ParameterDescription
arrayRequired. Source to query
predicateOptional. Invoked as (value, index, array); default _.identity

Return Value

Return ValueDescription
*New array without the matching trailing suffix

Lodash Examples

Example 1 — Official: Function Predicate

Drop trailing inactive users until the first active one from the end.

Lodash
var users = [
  { user: "barney",  active: true },
  { user: "fred",    active: false },
  { user: "pebbles", active: false }
];

_.dropRightWhile(users, function (o) { return !o.active; });
// → [{ user: "barney", active: true }]
Try It Yourself

How It Works

  1. Source. Three users; last two are inactive.
  2. Predicate. !o.active is truthy for inactive users.
  3. Drop suffix. pebbles and fred are removed from the end.
  4. Stop. barney is active → predicate falsy → keep the rest.

Example 2 — Official: Matches Object

Drop while the element deeply matches a partial object.

Lodash
var users = [
  { user: "barney",  active: true },
  { user: "fred",    active: false },
  { user: "pebbles", active: false }
];

_.dropRightWhile(users, { user: "pebbles", active: false });
// → [{ user: "barney", active: true }, { user: "fred", active: false }]
Try It Yourself

How It Works

  1. Shorthand. An object uses Lodash _.matches iteratee rules.
  2. Last item. pebbles matches → dropped.
  3. Next from end. fred does not match → stop.
  4. Result. barney and fred remain in order.

Example 3 — Official: MatchesProperty Pair

Drop while active === false using a [path, value] pair.

Lodash
var users = [
  { user: "barney",  active: true },
  { user: "fred",    active: false },
  { user: "pebbles", active: false }
];

_.dropRightWhile(users, ["active", false]);
// → [{ user: "barney", active: true }]
Try It Yourself

How It Works

  1. Pair form. ["active", false] means “property equals value”.
  2. Drop. Both trailing inactive users match and are removed.
  3. Stop. barney.active is true → not equal → stop.
  4. Keep. Only the active user remains.

Example 4 — Official: Property Shorthand

A string tests truthiness of that property — falsy at the end stops immediately.

Lodash
var users = [
  { user: "barney",  active: true },
  { user: "fred",    active: false },
  { user: "pebbles", active: false }
];

_.dropRightWhile(users, "active");
// → all three users (nothing dropped)
Try It Yourself

How It Works

  1. Property iteratee. "active" reads each object’s active field.
  2. Last value. pebbles.active is false (falsy).
  3. Stop at once. Falsy ends the drop — no items removed.
  4. Tip. Use this when trailing items are truthy and you want to skip that run.

Example 5 — Trailing Zeros

Only the contiguous trailing run is removed; an earlier zero stays.

Lodash
_.dropRightWhile([0, 1, 2, 0, 0], function (x) {
  return x === 0;
});
// → [0, 1, 2]
Try It Yourself

How It Works

  1. Trailing run. Last two values equal 0 → dropped.
  2. Break. 2 fails x === 0 → stop.
  3. Prefix kept. [0, 1, 2] — the leading zero is not removed.
  4. Rule. Unlike filter, earlier matches before the break stay put.

Browser & Runtime Support

_.dropRightWhile is a Lodash 4.x Array helper (since 3.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.0.0+

_.dropRightWhile()

Available in [email protected] full builds and the lodash/dropRightWhile modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.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
_.dropRightWhile Lodash 3.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import dropRightWhile from "lodash/dropRightWhile" for smaller builds. Not a native browser API — load Lodash first.

Frequently Asked Questions

_.dropRightWhile(array, predicate) walks from the end and drops elements while the predicate returns a truthy value. At the first falsy result it stops and returns a new array of everything to the left.
No. It returns a new array slice. The source array is left unchanged. Object elements inside are still shared by reference.
filter can remove matches anywhere. dropRightWhile only removes a contiguous suffix from the end — once the predicate fails, every earlier element is kept, even if it would match again.
You get an empty array. If the last element already fails the predicate, you get a shallow copy of the whole array.
Use import dropRightWhile from "lodash/dropRightWhile" or require("lodash/dropRightWhile") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.dropRightWhile.
Same as other Lodash iteratees: a function, a matches object, a matchesProperty pair like ["active", false], or a property name string. Default predicate is _.identity.

Next: _.dropWhile()

Trim a leading prefix with a predicate — the mirror of _.dropRightWhile.

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