Trusted answers to developer questions

What is the _.pull() method in Lodash?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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

Console
Implementation of the _.pull() method

Explanation

In the "HTML" tab:

  • Line 5: We import the lodash script.

In the "JavaScript" tab:

  • Line 2: We create the numbers array and populate it with a few values.
  • Line 5: We use the _.pull() method to remove the specified values.
  • Line 8: We print the numbers on the console.

Output

In the output, we see the original array from which the specified values are removed by the _.pull() method.

RELATED TAGS

lodash

CONTRIBUTOR

Shubham Singh Kshatriya
Did you find this helpful?