With an array of Javascript objects, I want to edit some values, then get an array of changed objects.
a=[{x:1,y:2},{x:2,y:4}];
b = _.clone(a);
// When I change b, a is also changed. I can no longer know the original a.
////////////////////////////////
a=[{x:1,y:2},{x:2,y:4}];
b = _.map( a, _.clone );
// When I change b, a is not changed,
// but I cannot find only the changed JSONs.
// Every JSON between a and b are considered different.
How to achieve the following?
a=[{x:1,y:2},{x:2,y:4}];
b = SOME_CLONE_OF_a;
b[0].x=5;
DIFF(b,a) // want to get [{x:5,y:2}]
DIFF(a,b) // want to get [{x:1,y:2}]
[Edited]
This question is not a duplicate of How do you clone an array of objects using underscore?
The answer provided there answered that question (how to clone), but does not answer my question (how to clone and know the difference).
The DEMO in this question uses the trick in that answer, and demostrated that it cannot find the wanted difference.