What is the _.pullAll() method in Lodash?
Overview
The _.pullAll() method in Lodash removes all the specified values from an array.
This is very similar to the _.pull() method. The only difference is that it accepts an array of values rather than comma-separated values.
Syntax
_.pullAll(array, values)
Parameters
This method accepts the following parameters:
array: This is the array to be modified.values: This is an array of values that are to be removed from the array.
Return value
This method mutates the original array and returns it.
Example
Explanation
In the "HTML" tab:
Line 5: We import the
lodashscript.
In the "JavaScript" tab:
Line 2: We create the
numbersarray and populate it with a few values.Line 5: We use the
_.pullAll()method to remove the specified values.Line 8: We print the
numberson the console.
Output
In the output, we see the original array from which the specified values are removed by the _.pullAll() method.