score:2

Accepted answer

you cannot compare objects you should check that an element with that id doesn't exists in the other array

here i used some that returns a boolean if he can find a match

const a = [{
  id: 1
}, {
  id: 2
}];
const b = [{
  id: 1
}, {
  id: 2
}, {
  id: 3
}];

const array3 = b.filter(obj => !a.some(({id}) => obj.id === id));

console.log(array3)

score:0

in your case, the following code gives all unique objects as an array, based on the id.

const a = [{
  id: 1
}, {
  id: 2
}];
const b = [{
  id: 1
}, {
  id: 2
}, {
  id: 3
}];

const array3 = b.filter(objb => a.some((obja) => objb.id !== obja.id));

console.log(array3)

score:0

a different approach with a symmetrically result.

const
    take = m => d => o => m.set(o.id, (m.get(o.id) || 0) + d),
    a = [{ id: 1 }, { id: 2 }],
    b = [{ id: 1 }, { id: 2 }, { id: 3 }],
    map = new map(),
    add = take(map),
    result = [];
    
a.foreach(add(1));
b.foreach(add(-1));
map.foreach((v, id) => v && result.push({ id }));
    
console.log(result);


Related Query

More Query from same tag