Given these two arrays:
const array1 = [
{"id": 1, "color": "black"},
{"id": 2, "color": "white"},
{"id": 3, "color": "orange"}
];
const array2 = [
{"id": 2, "color": "white"},
{"id": 4, "color": "purple"}
];
How could I remove the duplicates from the first array if found in the second, i.e. the result would be:
const filtered = [
{"id": 1, "color": "black"},
{"id": 3, "color": "orange"}
];
My code:
const filtered = array1.map(i => array2.filter(j => i["id"] !== j["id"]))
but it doesn't seem to work