Lodash | _.pullAll() Method

The _.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: This method accept two parameters as mentioned above and described below:

  • array: This parameter holds the array that need to be modify.
  • values: This parameter holds the values in an array that need to be remove from first array.

Return Value: It returns an array with all the values that are removed from the first array.

Example 1: This example removing the second array elements from the first array and returns the remaining elements.



filter_none

edit
close

play_arrow

link
brightness_4
code

const _ = require('lodash');
  
let ar = [1, 2, 3, 4, 5]
  
let rem = [1, 3]
  
let value = _.pullAll(ar, rem)
  
console.log(value)

chevron_right


Here, const _ = require('lodash') is used to import the lodash library into the file.

Output:

[ 2, 4, 5 ]

Example 2: This example removing the second array elements from the first array and returns the remaining elements.

filter_none

edit
close

play_arrow

link
brightness_4
code

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)

chevron_right


Output:

[ 2, 3, 3 ]

Example 3: This example removing the second array elements from the first array and returns the remaining elements.

filter_none

edit
close

play_arrow

link
brightness_4
code

const _ = require('lodash');
  
let ar = ['a', 'b', 'c', 'd']
  
let rem = ['b', 'c']
  
let value = _.pullAll(ar, rem)
  
console.log(value)

chevron_right


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

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.