Friday, October 24, 2025
HomeLanguagesJavascriptLodash _.remove() Method

Lodash _.remove() Method

Lodash _.remove() method is used to remove all elements from the array that predicate returns True and returns the removed elements in an array.

Syntax: 

_.remove(array, [predicate]);

Parameters:

  • array (Array) parameter holds the array that needs to be modified.
  • function(Function) parameter holds the function that is invoked per iteration.

Return Value:

It returns an array of removed elements.

Example 1: In this example, we are removing and returning the even numbers by using the _.remove() method.

Javascript




// Requiring the lodash library
const _ = require("lodash");
let x = [1, 2, 3, 4, 5];
 
let even = _.remove(x, function (n) {
    return n % 2 == 0;
});
 
console.log('Original Array ', x);
console.log('Removed element array ', even);


Output: 

Original Array  [ 1, 3, 5 ]
Removed element array  [ 2, 4 ]

Example 2: In this example, we are removing and returning the vowels by using the _.remove() method.

Javascript




const _ = require('lodash');
 
let x = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'];
 
let vowelArray = _.remove(x, function (n) {
 
    let vowels = ['a', 'e', 'i', 'o', 'u'];
 
    for (let i = 0; i < 5; i++) {
        if (n === vowels[i]) {
            return true;
        }
    }
});
 
console.log('Original Array ', x);
console.log('Removed element array ', vowelArray);


Output: 

Original Array  [ 'b', 'c', 'd', 'f', 'g', 'h' ]
Removed element array  [ 'a', 'e', 'i' ]

Example 3: In this example, we are removing and returning the integers by using the _.remove() method.

Javascript




const _ = require('lodash');
 
let x = ['a', 'b', 1, 5.6, 'e', -7, 'g', 4, 10.8];
 
let intsArray = _.remove(x, function (n) {
 
    return Number.isInteger(n);
});
 
console.log('Original Array ', x);
console.log('Removed element array ', intsArray);


Output: 

Original Array  [ 'a', 'b', 5.6, 'e', 'g', 10.8 ]
Removed element array  [ 1, -7, 4 ]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS