VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-differencewith-method/

⇱ Lodash _.differenceWith() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.differenceWith() Method

Last Updated : 12 Jul, 2025

Lodash _.differenceWith() method is similar to the _.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.

Syntax:

_.differenceWith(array, [values], [comparator]);

Parameters:

  • array: This parameter holds the array that values are checked or inspected.
  • 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 according to the condition explained above.

Example 1: In this example, we are finding the difference of the arrays by using the lodash _.differenceWith() method.

Output:

[1, 3]

Example 2: In this example, we are finding the difference of the arrays by using the lodash _.differenceWith() method.

Output:

[{b: 2}]

Example 3: In this example, we are finding the difference of the arrays by using the lodash _.differenceWith() method.

Output:

👁 Image

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

Comment