I'm trying to create a script for building an undo / redo function. Idea is my object should be added to a new key in array whenever it's updated.
I tested it with the following script :
var undoredo = new Array();
var obj = {
"0": {
"bg-pos": "",
"zoom": 3
}
}
for($i=1; $i < 5; $i++) {
obj[0]['zoom'] = obj[0]['zoom']+1;
undoredo.push(obj);
}
The problem here is zoom value should have been increased in each array key (3 to 7) but instead all zoom values are ended up with 7, the last added object's value. Is there any other way to add objects into array?