How to find and remove an elem that match in two different arrays?
For e.g.
let arr = [
{ startTimestamp: 1602675569525, name: "Pip" },
{ startTimestamp: 1602664708822, name: "Jimmy" },
{ startTimestamp: 1234, name: "Hero" }
];
let arr2 = [
{ startTimestamp: 1602675569525, name: "Pip" },
{ startTimestamp: 1602664708822, name: "Jimmy" },
{ startTimestamp: 505050, name: "Kit" }
];
If the startTimestamp
match then I would like to remove those elem. Output should be
[
{ startTimestamp: 1234, name: "Hero" },
{ startTimestamp: 505050, name: "Kit" }
]
I've tried this below but it only gives me [{startTimestamp: 1234, name: "Hero"}]
as I am only pushing arr[i] but I also need { startTimestamp: 505050, name: "Kit" }
let newArr = [];
for (let i = 0; i < arr.length; i++) {
if(arr[i].startTimestamp !== arr2[i].startTimestamp) {
newArr.push(arr[i])
}
}