Lodash _.dropWhile() method

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

What you’ll learn

  • How _.dropWhile(array, predicate) removes the longest leading run where your predicate is truthy.
  • Using functions versus Lodash iteratee shorthand (such as a property name string).
  • How dropWhile pairs with _.dropRightWhile() and fixed-count _.drop.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.drop() and _.dropRightWhile() on this site for context.

  • You can write a pure predicate (value, index, array) => boolean without mutating arguments.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.dropWhile trims a prefix defined by your predicate—ideal for skipping leading padding, blank header rows, or tokens until real data begins. It is the mirror image of _.dropRightWhile, which trims from the opposite end.

Non-destructive

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

Left-to-right scan

Evaluation starts at index 0 and stops on the first element that fails the predicate.

Predicate-driven

Unlike drop(n), you do not need to know the prefix length in advance.

Syntax

javascript
_.dropWhile(array, [predicate=_.identity])
  • array: source collection (array-like values are coerced).
  • predicate: invoked as (value, index, array); prefix elements are dropped while the result is truthy. Strings can select a property path like other Lodash iteratees.
  • Returns: a new array without the longest matching leading prefix.
1

Leading zeros

Only the contiguous leading run is removed; zeros later in the array stay put.

javascript
import dropWhile from "lodash/dropWhile";

dropWhile([0, 0, 1, 2, 0], (x) => x === 0);
// [1, 2, 0]
Try it Yourself
2

While a condition holds

Drop leading even numbers until an odd value breaks the predicate.

javascript
import dropWhile from "lodash/dropWhile";

dropWhile([2, 4, 6, 1, 3], (x) => x % 2 === 0);
// [1, 3]
Try it Yourself
3

Property shorthand

A string iteratee tests truthiness of a field; leading objects with a truthy skip are removed.

javascript
import dropWhile from "lodash/dropWhile";

dropWhile(
  [
    { id: 1, skip: true },
    { id: 2, skip: true },
    { id: 3, skip: false }
  ],
  "skip"
);
// [{ id: 3, skip: false }]
Try it Yourself

📋 dropWhile vs drop vs dropRightWhile

APITrim ruleDirection
_.dropWhile(arr, pred)Leading run while predicate is truthyStart of the array
_.drop(arr, n)Fixed n elements from the startStart of the array
_.dropRightWhile(arr, pred)Trailing run while predicate is truthyEnd of the array

Pitfalls to avoid

Prefix

Not the same as filter

filter can remove matches anywhere. dropWhile only removes a contiguous block at the beginning.

End

Trailing trim

For suffix predicates, use _.dropRightWhile() instead.

Truthiness

Iteratee shorthand

Property strings use truthiness of the resolved value; 0, "", and false count as falsy and stop the prefix.

❓ FAQ

No. Lodash returns a new array; the source array is unchanged.
Only a prefix: starting at index 0, elements are dropped while the predicate returns truthy. The first falsy result ends the scan; the rest of the array is kept as-is.
You receive an empty array.
Lodash returns a new empty array.
Use import dropWhile from "lodash/dropWhile" or require("lodash/dropWhile") for tree-shaking friendly bundles.

Summary

Did you know?

Lodash walks indices 0, 1, 2, … in order and stops at the first element for which the predicate returns a falsy value; everything from that index onward is kept unchanged.

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