The differenceWith()
function from lodash
library in JavaScript is used to compare two arrays and return a new array with values from the first array that do not exist in the second array, based on a given comparator function.
Here is an example of how to use the differenceWith()
function:
index.tsx413 chars13 lines
In the above example, arr1
and arr2
are two arrays that we want to compare. We have defined a comparator
function that compares values based on the id
property of each object. The differenceWith()
function is then called on arr1
and arr2
with the comparator
function as an argument, which returns a new array containing values from arr1
that do not exist in arr2
. The resulting array is stored in the result
variable and then logged to the console.
gistlibby LogSnag