JSFiddle - React, Tailwind, and code Playground

by alexche8

JavaScript

array1 = [{id: 1}, {id:2}];
array2 = [{id:1}, {id: 3}, {id:4}];
a = _.map(array1, function(obj){ return obj['id']});
b = _.map(array2, function(obj){ return obj['id']});
remove_ids = _.intersection(a,b);
all_objects = array1.concat(array2);
for( var key in all_objects){    
    if(remove_ids.indexOf(all_objects[key]['id']) != -1){
       delete all_objects[key];
    }
}
console.log(all_objects.sort());