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.
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
Contact Us