Js if you have the same object in two arrays, add attributes to the object.

[{id:"11"}, {id:"22"}, {id:"33"}] [{id:"11"}, {id:"33"}]
want the following results
[
{id:"11",follwed:true},
{id:"22",follwed:false},
{id:"33",follwed:true}
]

Jul.13,2021

var arr1 = [{id:'11'},{id:'22'},{id:'33'}];
var arr2 = [{id:'11'},{id:'33'}];
var arr = arr1.concat(arr2);
var obj = {}
var newArr = arr.reduce((pre, cur) => {
    obj[cur.id] ? '' : obj[cur.id] = true && pre.push(cur);
    return pre
}, [])
console.log(newArr)
Menu