Ramda.js R.dropWhile() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A list helper that skips items from the start while a test returns true, then returns everything after — starting with the first item that fails. It works on arrays and strings and never changes the original. Part of Ramda List since v0.9.0 (stable — not deprecated, experimental, or non-standard).

Why not filter? R.reject removes matches everywhere. dropWhile only trims a leading run — perfect for headers, leading zeros, or already-finished items at the top of a list.

Syntax

Call R.dropWhile. Start with this line.

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

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

Library declarations
Ramda
R.dropWhile(pred, list)

Parameters

ParameterDescription
predRequired. value → Boolean — truthy means "skip"
listRequired. An array or a string

Return Value

Return ValueDescription
*A new array (or string) from the first failing item to the end

Ramda Examples

Example 1 — Official Number Sample

Skip small numbers at the start, keep everything from the first big one.

Ramda
const lteTwo = x => x <= 2;

console.log(R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]));
// → [3, 4, 3, 2, 1]
Try It Yourself

How It Works

  1. The test. lteTwo returns true for numbers that are 2 or less — those get skipped.
  2. Skip. 1 and 2 pass the test → dropped.
  3. Stop. 3 fails the test, so the walk ends and 3 is kept.
  4. Keep the rest. The final 2 and 1 stay, even though they would pass — only the front is trimmed.

Example 2 — Strings In, Strings Out

The official string sample, plus trimming leading zeros.

Ramda
console.log(R.dropWhile(x => x !== "d", "Ramda"));
// → "da"

console.log(R.dropWhile(c => c === "0", "000420"));
// → "420"
Try It Yourself

How It Works

  1. One character at a time. For a string, the test receives each character.
  2. “Ramda”. "R", "a", "m" are not "d" → dropped; "d" stops the walk → "da".
  3. Leading zeros. The three "0"s are dropped; "4" stops it. The "0" at the end stays → "420".
  4. Type kept. Both results are strings, not arrays of characters.

Example 3 — Skip a Comment Header

Drop the comment lines at the top of a config file, but keep comments further down.

Ramda
const lines = ["# config", "# v2", "port=80", "# note", "host=x"];

console.log(R.dropWhile(R.startsWith("#"), lines));
// → ["port=80", "# note", "host=x"]
Try It Yourself

How It Works

  1. Ready-made test. R.startsWith("#") is curried, so it already is a one-argument test.
  2. Skip the header. "# config" and "# v2" start with # → dropped.
  3. Stop. "port=80" fails the test → the walk ends there.
  4. Middle comment stays. "# note" comes after the stop, so it is kept.

Example 4 — Skip Finished Items in a List of Objects

Find the remaining work in a task queue where finished tasks sit at the top.

Ramda
const tasks = [
  { id: 1, done: true },
  { id: 2, done: true },
  { id: 3, done: false },
  { id: 4, done: true }
];

const remaining = R.dropWhile(R.prop("done"), tasks);

console.log(R.pluck("id", remaining));
// → [3, 4]
Try It Yourself

How It Works

  1. Property as test. R.prop("done") returns each task’s done value, which is already true / false.
  2. Skip. Tasks 1 and 2 are done → dropped.
  3. Stop. Task 3 is not done → kept, and the walk ends.
  4. Show ids. Task 4 stays because it comes after the stop. R.pluck("id") prints [3, 4].

Example 5 — dropWhile vs takeWhile vs reject

Same test, three different answers.

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

console.log(R.takeWhile(lteTwo, nums)); // → [1, 2]
console.log(R.dropWhile(lteTwo, nums)); // → [3, 4, 3, 2, 1]
console.log(R.reject(lteTwo, nums));    // → [3, 4, 3]
Try It Yourself

How It Works

  1. takeWhile. R.takeWhile keeps the leading run: [1, 2].
  2. dropWhile. Throws that same run away and keeps the rest: [3, 4, 3, 2, 1].
  3. Two halves. Put together, takeWhile + dropWhile give back the original list.
  4. reject. R.reject tests every item, so the trailing 2 and 1 are removed too: [3, 4, 3].

Browser & Runtime Support

R.dropWhile is a Ramda List helper since v0.9.0. It uses only indexing and slicing, so it runs anywhere Ramda runs — browsers via CDN or bundler, and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.9.0+

R.dropWhile()

Support depends on the Ramda version you load, not on a browser feature. Your own test must also be valid in that runtime — e.g. arrow functions need an ES2015 engine.

100% Modern browsers & runtimes
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Chromium-based
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Android WebView Modern WebView
Full support
Internet Explorer Not a target for current Ramda releases
Legacy
Node.js Maintained LTS · npm install ramda
Supported
Bun import from "ramda"
Supported
Deno import from "npm:ramda"
Supported
R.dropWhile Ramda 0.9.0+

Bottom line: Safe for production in any modern browser or JavaScript runtime once Ramda is loaded. The labs on this page use [email protected] from a CDN.

Frequently Asked Questions

R.dropWhile(pred, list) skips items from the start while pred returns true, then returns everything from the first failing item onward. The docs sample is R.dropWhile(x => x <= 2, [1, 2, 3, 4, 3, 2, 1]) //=> [3, 4, 3, 2, 1].
No. It stops at the first item that fails the test and keeps the rest unchanged. In [1, 2, 3, 4, 3, 2, 1], the 2 and 1 at the end stay. To remove every match, use R.reject.
Yes. A string in gives a string out: R.dropWhile(x => x !== 'd', 'Ramda') //=> 'da'. The predicate receives one character at a time.
takeWhile keeps the leading run that dropWhile throws away, so the two split a list in two. dropLastWhile does the same skipping, but from the end of the list.
No. Ramda passes only the value. If you need the index, wrap it: R.addIndex(R.dropWhile)((x, i) => i < 2, list).
No. R.dropWhile has been part of Ramda since v0.9.0 and is stable — not deprecated, experimental, or non-standard.

Next: R.endsWith()

Learn how to check whether a list or string ends with a given suffix.

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