Lodash _.differenceWith() Method
The _.differenceWith() method is similar to _.difference() method that returns the array containing the values that are in the first array not in the second array but in _.differenceWith() 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.
_.differenceWith(array, [values], [comparator])
Parameters: This method accept three parameters as mentioned above and described below:
- array: This parameter holds the array that values are checked or inspect.
- 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 according to the condition explained above.
const _ = require('lodash') is used to import the lodash library into the file.
So, here each element of the first array is compared with each element of the second array according to the third comparator, in our case its _.isEqual. So, if the value becomes equal it removes it.
Please Login to comment...