Lodash _.pullAll() method is used to remove all the values from the first given array that are given in the second array.
Syntax:
_.pullAll(array, values);
Parameters:
- array: This parameter holds the array that needs to be modified.
- values: This parameter holds the values in an array that need to be removed from the first array.
Return Value:
It returns an array with all the values that are removed from the first array.
Example 1: In this example, it removes the second array of elements from the first array and returns the remaining elements.
javascript
const _ = require( 'lodash' );
let ar = [1, 2, 3, 4, 5]
let rem = [1, 3]
let value = _.pullAll(ar, rem)
console.log(value)
|
Output:
[ 2, 4, 5 ]
Example 2: In this example, it removes the second array of elements from the first array and returns the remaining elements.
javascript
const _ = require( 'lodash' );
let ar = [1, 2, 3, 1, 3, 4, 1, 5]
let rem = [1, 4, 5]
let value = _.pullAll(ar, rem)
console.log(value)
|
Output:
[ 2, 3, 3 ]
Example 3: In this example, it removes the second array elements from the first array and returns the remaining elements.
javascript
const _ = require( 'lodash' );
let ar = [ 'a' , 'b' , 'c' , 'd' ]
let rem = [ 'b' , 'c' ]
let value = _.pullAll(ar, rem)
console.log(value)
|
Output:
[ 'a', 'd' ]
Note: This will not work in normal JavaScript because it requires the library lodash to be installed.
Reference: https://lodash.com/docs/4.17.15#pullAll
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
03 Nov, 2023
Like Article
Save Article