I have two arrays, old and new, which contain objects in each position. How can I synchronize or find a delta (that is, what's new is updated and deleted from the new array compared to the old array)
var o = [
{id:1, title:"title 1", type:"foo"},
{id:2, title:"title 2", type:"foo"},
{id:3, title:"title 3", type:"foo"}
];
var n = [
{id:1, title:"title 1", type:"foo"},
{id:2, title:"title updated", type:"foo"},
{id:4, title:"title 4", type:"foo"}
];
With the above data, using id as the key, we find that the element with id = 2 has an updated header, the element with id = 3 is deleted, and the element with id = 4 is new.
Is there an existing library that has useful functions, or is it a case of a loop and an inner loop, compare each line ... for example.
for(var i=0, l=o.length; i<l; i++)
{
for(var x=0, ln=n.length; x<ln; x++)
{
}
}
Do this comparison three times to find a new, updated, and deleted?