How to use Lodash _.without() Method In Lodash

In this approach, we use the _.without method from Lodash with the original list and the element ‘banana’ as arguments, which returns a new array excluding ‘banana’.

Command to install lodash:

npm i lodash

Example: The below example uses without function to remove an element from a list in lodash.

JavaScript
const _ = require('lodash');
let list = ['apple', 'banana', 'cherry', 'orange'];
let res = _.without(list, 'banana');
console.log(res); 

Output:

[ 'apple', 'cherry', 'orange' ]

How to Remove an Element from a list in Lodash?

To remove an element from a list, we employ Lodash functions such as without, pull, or reject. These methods enable us to filter out elements from the list based on specific conditions, effectively excluding those that match the criteria.

Below are the approaches to remove an element from a list in lodash:

Table of Content

  • Using Lodash _.without() Method
  • Using Lodash _.pull() Method
  • Using Lodash _.reject() Method

Similar Reads

Using Lodash _.without() Method

In this approach, we use the _.without method from Lodash with the original list and the element ‘banana’ as arguments, which returns a new array excluding ‘banana’....

Using Lodash _.pull() Method

In this approach, we are using the _.pull method from Lodash directly on the list, removing the element ‘css’ and modifying the list in place, resulting in the updated list without ‘css’....

Using Lodash _.reject() Method

In this approach, we are using the _.reject method from Lodash with a predicate that checks for equality with ‘banana’, creating a new array excluding ‘banana’ and keeping other elements in the list....

Contact Us