This method is like union except that it accepts comparator which is invoked to compare elements of arrays. Result values are chosen from the first array in which the value occurs. The comparator is invoked with two arguments: (arrVal, othVal).
union
comparator
arrays
Optional
The arrays to inspect.
Returns the new array of combined values.
5.13.0
[[difference]], [[union]], [[unionBy]], [[without]], [[xor]], [[xorBy]]
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]unionWith(objects, others, isEqual)// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] Copy
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]unionWith(objects, others, isEqual)// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
This method is like
union
except that it acceptscomparator
which is invoked to compare elements ofarrays
. Result values are chosen from the first array in which the value occurs. The comparator is invoked with two arguments: (arrVal, othVal).