Ramda.js R.dropLastWhile() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.dropLastWhile(pred, list) checks items from the end and removes them while pred returns a truthy value. It stops at the first item that fails and returns a new list (or string) of everything before that point (official Ramda docs).

Added in v0.16.0: R.dropLastWhile is stable — not deprecated, experimental, or non-standard. Note: it removes only the trailing run of matches; matching items earlier in the list are kept.

Syntax

Call R.dropLastWhile. Start with this line.

Ramda
R.dropLastWhile(pred, list) or R.dropLastWhile(pred)(list)
CallWhat it does
R.dropLastWhile(pred, list) or R.dropLastWhile(pred)(list)Primary signature.
R.dropLastWhile(...)Call the list helper.

Prefer import { dropLastWhile } from "ramda" when you want a named import.

Library declarations
Ramda
R.dropLastWhile(pred, list) or R.dropLastWhile(pred)(list)

Parameters

ParameterDescription
predRequired. Called with one item; truthy means "remove it and keep going"
listOptional. Array or string; omit it to get a reusable function

Return Value

Return ValueDescription
*A new array or string without the trailing matches

Ramda Examples

Example 1 — Official Samples

Remove trailing numbers that are at most 3, then trailing characters that are not 'd' — from the Ramda docs.

Ramda
const lteThree = x => x <= 3;

console.log(R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]));  // [1, 2, 3, 4]
console.log(R.dropLastWhile(x => x !== 'd', 'Ramda'));          // 'Ramd'
Try It Yourself

How It Works

  1. From the right. The trailing 1, 2, 3 pass x <= 3, so they are removed.
  2. Stop. 4 fails the test, so the walk stops and [1, 2, 3, 4] is kept.
  3. Strings. In 'Ramda', the last 'a' is not 'd', so it is removed.
  4. Stop at d. 'd' fails x !== 'd', so the result is 'Ramd'.

Example 2 — Remove Trailing Blanks

Clean up empty values at the end of a list while keeping the ones in the middle.

Ramda
const scores = [1, null, 2, undefined, null];
const cells = ['a', '', 'b', '', ''];

console.log(R.dropLastWhile(R.isNil, scores));    // [1, null, 2]
console.log(R.dropLastWhile(R.isEmpty, cells));   // ['a', '', 'b']
Try It Yourself

How It Works

  1. Missing values. R.isNil removes the trailing null and undefined.
  2. Stop at data. 2 is not nil, so the walk stops there.
  3. Middle stays. The null between 1 and 2 is kept — it is not at the end.
  4. Empty strings. R.isEmpty does the same for trailing '' cells.

Example 3 — Trim Both Ends

Pair it with R.dropWhile to strip padding zeros from the start and the end.

Ramda
const isZero = R.equals(0);

const trimZeros = R.pipe(
  R.dropWhile(isZero),
  R.dropLastWhile(isZero)
);

console.log(trimZeros([0, 0, 7, 0, 8, 0]));   // [7, 0, 8]
Try It Yourself

How It Works

  1. Test. R.equals(0) returns true for zeros.
  2. Start. R.dropWhile removes the leading 0, 0 → [7, 0, 8, 0].
  3. End. R.dropLastWhile removes the trailing 0 → [7, 0, 8].
  4. Middle stays. The 0 between 7 and 8 is real data, so neither step touches it.

Example 4 — Strip Trailing Punctuation

Works like trimEnd(), but for any characters you choose.

Ramda
const isPunct = c => '.!?'.includes(c);
const trimPunct = R.dropLastWhile(isPunct);

console.log(trimPunct('Loading...'));   // 'Loading'
console.log(trimPunct('Really?!'));     // 'Really'
console.log(trimPunct('Hi. Bye.'));     // 'Hi. Bye'
Try It Yourself

How It Works

  1. Character test. isPunct is true for '.', '!', and '?'.
  2. Curried. R.dropLastWhile(isPunct) returns a reusable string trimmer.
  3. Trailing only. '...' and '?!' are removed until a letter stops the walk.
  4. Middle stays. The '.' after 'Hi' is kept. For whitespace only, native trimEnd() is enough.

Example 5 — dropLastWhile vs Its Neighbours

Same list, same test, four different results — pick the one that matches your goal.

Ramda
const lteThree = x => x <= 3;
const nums = [1, 2, 3, 4, 3, 2, 1];

console.log(R.dropLastWhile(lteThree, nums));   // [1, 2, 3, 4]
console.log(R.dropWhile(lteThree, nums));       // [4, 3, 2, 1]
console.log(R.takeLastWhile(lteThree, nums));   // [3, 2, 1]
console.log(R.reject(lteThree, nums));          // [4]
Try It Yourself

How It Works

  1. dropLastWhile. Removes the trailing 3, 2, 1.
  2. dropWhile. R.dropWhile removes the leading 1, 2, 3 instead.
  3. takeLastWhile. R.takeLastWhile keeps exactly the part that dropLastWhile removes.
  4. reject. R.reject removes every match, wherever it is, leaving only [4].

Browser & Runtime Support

R.dropLastWhile() is plain JavaScript inside Ramda 0.16.0+. It uses a simple loop and native slice (ES3), so it works wherever Ramda loads.

✓ Ramda 0.16.0+ · Any JS runtime

Ramda.js R.dropLastWhile()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda 0.16+
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
R.dropLastWhile() Universal

Bottom line: Safe in any project on Ramda 0.16 or newer; older versions have no R.dropLastWhile. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.dropLastWhile(pred, list) checks items from the end and removes them while the predicate returns a truthy value. It stops at the first item that fails and keeps everything before it. With lteThree = x => x <= 3, R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]) returns [1, 2, 3, 4].
No. It only removes the trailing run of matches. In [1, 2, 3, 4, 3, 2, 1], the 1, 2, and 3 before the 4 stay because the walk stops at 4. To remove every match, use R.reject.
R.dropWhile removes matching items from the start, R.dropLastWhile removes them from the end, and R.dropLast removes a fixed number of items from the end without any test.
If every item matches, the result is empty: [] or ''. If the last item already fails, nothing is removed and you get a full copy. The original list is never changed.
Yes. It tests one character at a time and returns a string, so R.dropLastWhile(x => x !== 'd', 'Ramda') returns 'Ramd'.
No. R.dropLastWhile was added in Ramda v0.16.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.dropRepeats()

Remove consecutive duplicates from a list.

R.dropRepeats() 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.

6 people found this page helpful