I\'d like to use the _.union
function to create a union of two arrays of objects. Union works with arrays of primitives only as it uses === to examine if two va
A non pure lodash way to do this but using the array.concat function you are able to do this pretty simply along uniq()
:
var objUnion = function(array1, array2, matcher) {
var concated = array1.concat(array2)
return _.uniq(concated, false, matcher);
}
An alternative approach would be to use flatten() and uniq():
var union = _.uniq(_.flatten([array1, array2]), matcherFn);