What is the _.pull() method in Lodash?
Overview
The _.pull() method in Lodash removes all the specified values from an array. This method mutates the original array.
Syntax
_.pull(array, [values])
_.pull() syntax
Parameters
This method accepts the following parameters:
array: This is the array to be modified.values: These are the comma-separated 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
_.pull()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 _.pull() method.