Js array take more and less

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

how to calculate

in b that b does not have in a

according to the meaning of the question, you want to get {id: 4}] ?

that a does not exist in b.
let a = [{id:1},{id:2},{id:3}];
let b = [{id:1},{id:2},{id:4}];
let result = b.filter(el => {
    return !(a.find(item => el.id === item.id));
});
console.log(result);
// [{id: 4}]

in the same way, you can get [{id: 3}] .


take the

that b does not have in a.

1

var result = new Object();
var a=[{id:1},{id:2},{id:3}];
var b=[{id:1},{id:2},{id:4}];
var c= a.concat(b);
c.forEach(x=>(result[x.id]&&(result[x.id].countPP))||(result[x.id]=x)&&(x.count=1));
c.filter(x=>x.count==1);
Menu