xxxxxxxxxx
var arr1 = [{ name: 'fred' }, { name: 'bill' }, { name: 'ted' }, { name: 'james' }],
arr2 = [{ name: 'toString' }, { name: 'spil' }, { name: 'fred' }, { name: 'bill' }, { name: 'paul' }, { name: 'stone' }],
hash = Object.create(null);
arr1.forEach(function (a) {
hash[a.name] = true;
});
arr2.forEach(function (a) {
hash[a.name] || arr1.push(a);
});
console.log(arr1);
Run code snippet