Ramda.js R.dropLast() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.dropLast(n, list) returns a new list or string with the last n items removed (official Ramda docs). The original value is never changed, and removing more items than exist simply gives an empty result.

Added in v0.16.0: R.dropLast is stable — not deprecated, experimental, or non-standard. Note: unlike native slice(0, -n), an n of 0 keeps every item instead of returning [].

Syntax

Call R.dropLast. Start with this line.

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

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

Library declarations
Ramda
R.dropLast(n, list) or R.dropLast(n)(list)

Parameters

ParameterDescription
nRequired. How many items to remove from the end; 0 or negative removes nothing
listOptional. Array or string; omit it to get a reusable function

Return Value

Return ValueDescription
*A new array or string of the remaining items

Ramda Examples

Example 1 — Official Samples

Remove 1, 2, 3, and 4 items from the end of a list, then 3 characters from a string — straight from the Ramda docs.

Ramda
const words = ['foo', 'bar', 'baz'];

console.log(R.dropLast(1, words));     // ['foo', 'bar']
console.log(R.dropLast(2, words));     // ['foo']
console.log(R.dropLast(3, words));     // []
console.log(R.dropLast(4, words));     // []
console.log(R.dropLast(3, 'ramda'));   // 'ra'
Try It Yourself

How It Works

  1. Remove from the end. R.dropLast(1, words) removes 'baz' and keeps the rest.
  2. Bigger n. Removing 2 leaves only 'foo'; removing 3 empties the list.
  3. Too many. Removing 4 from a 3-item list is not an error — you just get [].
  4. Strings. A string returns a string: removing 'mda' leaves 'ra'.

Example 2 — Remove a Fixed-Length Suffix

Give R.dropLast only n to build a reusable string helper.

Ramda
const removeExt = R.dropLast(4);

console.log(removeExt('photo.jpg'));    // 'photo'
console.log(removeExt('report.pdf'));   // 'report'
console.log(R.dropLast(1, 'Hello!'));   // 'Hello'
Try It Yourself

How It Works

  1. Curried. R.dropLast(4) has no string yet, so it returns a function that waits for one.
  2. Four characters. '.jpg' and '.pdf' are both 4 characters long, so they are removed.
  3. One character. R.dropLast(1, 'Hello!') removes only the '!'.
  4. Fixed length only. 'notes.html' would lose just 'html'; for variable endings, split on the dot instead.

Example 3 — Trim Both Ends

Pipe R.drop and R.dropLast to remove a header row and a footer row.

Ramda
const rows = ['name', 'Ana', 'Ben', 'Cy', 'TOTAL'];

const bodyRows = R.pipe(R.drop(1), R.dropLast(1));

console.log(bodyRows(rows));   // ['Ana', 'Ben', 'Cy']
console.log(rows.length);      // 5
Try It Yourself

How It Works

  1. Header. R.drop(1) removes 'name' from the start.
  2. Footer. R.dropLast(1) then removes 'TOTAL' from the end.
  3. Pipeline. R.pipe runs the two steps left to right as one reusable function.
  4. No mutation. rows still has all 5 items afterwards.

Example 4 — Why Not slice(0, -n)?

The native trick fails when n is 0; R.dropLast handles every n safely.

Ramda
const nums = [1, 2, 3];
const n = 0;

console.log(nums.slice(0, -n));      // []  surprise!
console.log(R.dropLast(n, nums));    // [1, 2, 3]
console.log(R.dropLast(-1, nums));   // [1, 2, 3]
console.log(R.dropLast(10, nums));   // []
Try It Yourself

How It Works

  1. The trap. -0 is just 0, so nums.slice(0, -0) means “stop at index 0” and returns [].
  2. Ramda is safe. R.dropLast(0, nums) keeps 3 − 0 = 3 items, a full copy.
  3. Negative. -1 would keep 4 items, which is more than exist, so you get all 3.
  4. Too large. 10 is not less than the length, so nothing is kept: [].

Example 5 — dropLast vs init vs takeLast

Three ways to work with the end of a list — remove n, remove one, or keep n.

Ramda
const nums = [1, 2, 3, 4, 5];

console.log(R.dropLast(2, nums));   // [1, 2, 3]
console.log(R.init(nums));          // [1, 2, 3, 4]
console.log(R.takeLast(2, nums));   // [4, 5]
Try It Yourself

How It Works

  1. dropLast. Removes the last two items, 4 and 5.
  2. init. R.init always removes exactly one item from the end — the same as R.dropLast(1).
  3. takeLast. R.takeLast(2) is the opposite: it keeps only 4 and 5.
  4. Pair. R.dropLast(2) and R.takeLast(2) together give back the whole list.

Browser & Runtime Support

R.dropLast() is plain JavaScript inside Ramda 0.16.0+. It copies with native slice (ES3) for arrays and strings, so it works wherever Ramda loads.

✓ Ramda 0.16.0+ · Any JS runtime

Ramda.js R.dropLast()

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.dropLast() Universal

Bottom line: Safe in any project on Ramda 0.16 or newer; older versions have no R.dropLast. 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.dropLast(n, list) returns a new list without the last n items. It also works on strings. The official samples are R.dropLast(1, ['foo', 'bar', 'baz']), which returns ['foo', 'bar'], and R.dropLast(3, 'ramda'), which returns 'ra'.
You get an empty result: [] for arrays and '' for strings. It is not an error, and the original list is never changed.
Because n = 0 breaks it: list.slice(0, -0) is the same as list.slice(0, 0), which returns []. R.dropLast(0, list) correctly returns a full copy, and a negative n also keeps every item.
R.drop(n, list) removes the first n items, R.dropLast(n, list) removes the last n items, and R.takeLast(n, list) keeps only the last n items.
R.init(list) always removes exactly one item from the end, so it equals R.dropLast(1, list). R.dropLast lets you choose how many items to remove.
No. R.dropLast was added in Ramda v0.16.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.dropLastWhile()

Remove items from the end of a list while a test passes.

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