The Wayback Machine - https://web.archive.org/web/20240118182201/https://www.geeksforgeeks.org/lodash-_-pullallby-method/
Open In App
Related Articles

Lodash _.pullAllBy() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The _.pullAllBy() method is used to remove the values from the original array by iterating over each element in the array by using the Iteratee function. It is almost the same as _.pullAll() function.

Syntax:

_.pullAllBy(array, values, [iteratee=_.identity])

Parameters: This method accepts two parameters as mentioned above and described below:

  • array: This parameter holds the array that needs to be modified.
  • values: This parameter holds the values in an array that needs to be removed from the first array.
  • Iteratee: This is the function that Iteratee over each element.

Return Value: It returns an array.

Note: If the iteratee function is not given then _.pullAllBy() function act as _.pullAll() function.  

Example 1: 

Javascript




// Requiring the lodash library
const _ = require("lodash");
   
// Original array
let array1 = [1, 2, 3, 4.2]
   
// Array to be subtracted
let val = [2, 3, 3, 5]
 
// Printing the original array
console.log("Before : ", array1); 
   
// Array after _.pullAllBy() 
// method where Math.double is the
// comparable function
_.pullAllBy(array1, val, Math.double);
   
// Printing the output
console.log("After : ", array1);


Output:

Example 2:

Javascript




// Requiring the lodash library
const _ = require("lodash");
   
// Original array
let array1 = [1, 2, 3, 4.2]
let array2 = [1, 2, 3, 4.2]
   
// Value array to be subtracted
let val = [2, 3, 4, 5]
 
// Printing the original array
console.log("Before : ", array1);
   
// Array after _.pullAllBy()
// method where Math.double is the
// comparable function
_.pullAllBy(
    array1, val, Math.floor);
   
// Array after _.pullAllBy function
// where no comparable function is given
 _.pullAllBy(array2, val); 
   
// Printing the output
console.log("When compare funct is given: ", 
        array1);
   
// Printing the output
console.log("When compare funct is not given: ", 
        array2);


Output:

Note: This will not work in normal JavaScript because it requires the library lodash to be installed.


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

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!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 28 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials