Lodash _.pullAllWith() Method
Last Updated :
03 Nov, 2023
Lodash_.pullAllWith() method is similar to the _.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:
- array: This parameter holds the array that needs to be modified.
- values: This parameter holds the value that needs to be removed.
- comparator: This parameter holds the comparison invoked per element.
Return Value:
This method returns an array.
Example 1: In this example, we are removing the giving array from another array that has the same value as it and printing the result in the console.
Javascript
const _ = require( "lodash" );
let x = [1, 2, 3]
let y = [2, 4, 5]
console.log( "Before : " , x);
_.pullAllWith(x, y, _.isEqual);
console.log( "After : " , x);
|
Output:
Example 2: In this example, we are removing the giving array from another array that has the same value as it and printing the result in the console.
Javascript
const _ = require( "lodash" );
let x = [{ a: 1 }, { b: 2 }, 6]
let y = [{ a: 1 }, 7, 6]
console.log( "Before : " , x);
_.pullAllWith(x, y, _.isEqual);
console.log( "After : " , x);
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...