consider below 2 array of objects, say arr1 and arr2.
based on id, if any new item exist in arr2 copy item to arr1 and remove item from arr1 if that item not present in arr2.
const arr1 = [
{name: "name1", id: 1},
{name: "name2", id: 2},
{name: "name3", id: 3}
];
const arr2 = [
{name: "name1", id: 1},
{name: "name2", id: 4},
{name: "name3", id: 3}
];
required output
output = `[
{name: "name1", id: 1},
{name: "name3", id: 3},
{name: "name2", id: 4}
]`