Wednesday, September 25, 2024
Google search engine
HomeLanguagesJavascriptLodash _.pullAllWith() Method

Lodash _.pullAllWith() Method

The _.pullAllWith() method is similar to _.pullAll() method that returns the first array containing the values that are in the first array not in the second array but in _.pullAllWith() all the elements of the first array are compared with the second array by applying comparison provided in third. It may be a little complex to understand by reading this but it will become simple when you see the example.

Syntax:

_.pullAllWith(array, values, [comparator])

Parameters: This method accept three parameters as mentioned above and described below:

  • array: This parameter holds the array that need to be modify.
  • values: This parameter holds the value that need to be removed.
  • comparator: This parameter holds the comparison invoked per element.

Return Value: This method returns an array. 

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.

Javascript




// Requiring the lodash library 
const _ = require("lodash"); 
    
// Original array 
let x = [1, 2, 3] 
    
// Value array to be subtracted 
let y = [2, 4, 5] 
  
// Printing the original array 
console.log("Before : ", x);
    
// Array after _.pullAllWith() 
// method where _.isEqual is the 
// comparator
_.pullAllWith(x, y, _.isEqual);
    
// Printing the output 
console.log("After : ",x);


Output:

Example 2:

Javascript




// Requiring the lodash library 
const _ = require("lodash"); 
    
// Original array 
let x = [{a: 1}, {b: 2}, 6]  
    
// Value array to be subtracted 
let y = [{a: 1}, 7, 6] 
  
// Printing the original array 
console.log("Before : ", x);
    
// Array after _.pullAllWith() 
// method where _.isEqual is the 
// comparator
_.pullAllWith(x, y, _.isEqual);
    
// Printing the output 
console.log("After : ",x);


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments