Lodash _.remove() method

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

What you’ll learn

  • How _.remove(array, predicate) deletes elements wherever the predicate returns a truthy value.
  • That the source array is mutated while Lodash returns an array of the removed values.
  • When predicates beat value-based helpers such as _.pull().
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Comfort with _.findIndex()-style predicates helps; contrast with value removals in _.pull() and index removals in _.pullAt().

  • You understand that shrinking an array shifts indexes for elements that remain.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.remove is the in-place sibling of filtering logic: walk the array, splice out anything your predicate approves, and collect those evicted values into the returned array—ideal when you still need the rejects for logging, undo buffers, or analytics.

In place

The argument array loses matching entries immediately; plan clones when other owners still need the old snapshot.

Predicate driven

Express rules as functions instead of enumerating literals—great for ranges, nested fields, or dynamic criteria.

Removed chunk

The return value mirrors _.pullAt’s “what got extracted” pattern, but membership comes from predicate truthiness.

Syntax

javascript
_.remove(array, predicate)
  • array: collection to mutate (array-like values are coerced).
  • predicate: invoked per element as predicate(value, index, array); truthy results schedule removal.
  • Returns: a new array containing every removed element, ordered by removal.
1

Predicate on primitives

Strip even numbers; the leftover odds stay in nums while removed captures everything that failed the keep rule.

javascript
import remove from "lodash/remove";

const nums = [1, 2, 3, 4];
const removed = remove(nums, (n) => n % 2 === 0);
// nums is now [1, 3]; removed is [2, 4]
Try it Yourself
2

Objects by field

Predicates shine when rows carry structured data—here everything with archived: true vanishes from the live list.

javascript
import remove from "lodash/remove";

const rows = [
  { id: 1, archived: false },
  { id: 2, archived: true },
  { id: 3, archived: false }
];
const archived = remove(rows, (r) => r.archived === true);
// rows keeps active records; archived holds the removed rows
Try it Yourself
3

Using index

The second argument is the live index—handy for trimming tails without hard-coding splice arithmetic.

javascript
import remove from "lodash/remove";

const xs = ["a", "b", "c", "d"];
remove(xs, (_v, i, arr) => i >= arr.length - 2);
// xs is now ["a", "b"] — last two entries removed
Try it Yourself

📋 _.remove vs _.pull vs _.filter vs _.reject

APIMutationReturns
_.remove(array, pred)Mutates arrayArray of removed elements
_.pull(array, ...values)Mutates arraySame array reference after stripping literals
_.filter(array, pred)Does not mutateNew array of kept elements
_.reject(array, pred)Does not mutateNew array omitting predicate matches

Pitfalls to avoid

Share

Hidden aliasing

Other holders of the same array reference see the mutation instantly—clone first when isolation matters.

Pred

Side effects inside predicates

Keep predicates pure; pushing to the same array or relying on external counters mid-removal invites subtle bugs as indexes shift.

Return

Expecting survivors

The returned array is the removed slice. Read array itself after the call when you need what stayed behind.

❓ FAQ

Yes. Matching elements are deleted in place so length and indexes shift. Lodash returns a new array containing only the removed values, in removal order.
The predicate is invoked as predicate(value, index, array)—the same trio familiar from _.filter-style iteratees.
filter leaves the source untouched and returns a new array of kept elements. remove mutates the source and returns the removed elements instead.
reject returns a brand-new array without the rejected elements and does not mutate the input. remove edits the original array and gives you the stripped-out values.
Use import remove from "lodash/remove" or require("lodash/remove") for tree-shaking friendly bundles.

Summary

  • Purpose: _.remove(array, predicate) deletes predicate matches in place and returns those elements as a new array.
  • Immutable alternative: pair filter / reject when you must preserve the original ordering snapshot.
  • Next: Lodash _.reverse(), _.pullAt() (previous), or the array methods hub.
Did you know?

Unlike _.pull(), which matches explicit values with SameValueZero, _.remove deletes items whenever your predicate says so—similar to how _.pullAt() hands back the removed chunk, but driven by logic instead of indexes.

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