function setobjprop(ind, prop, v) {
if (undo_arr.length > 0) {
console.log("C" + undo_arr.length + ": " + undo_arr[0][0].rotate);
}
console.log(ind + ":" + prop + ":" + v);
user_img[ind][prop] = v;
if (undo_arr.length > 0) {
console.log("D" + undo_arr.length + ": " + undo_arr[0][0].rotate);
}
undo_arr.push(user_img.slice(0));
console.log(undo_arr[0][0].rotate);
console.log(prop + " -> " + v);
if (undo_arr.length > 10) {
undo_arr.shift();
}
redrawCanvas(ind);
}
I have an array of objects called user_img
, now I wrote a function to update the value of an object at a particular index within this array, then I am trying to store a copy of this entire array in another array called undo_arr
. But all copies of the array in the undo_arr seems to point to the user_img
array, because the object modification seems to reflect upon all copies previously stored in the undo_arr
. Any idea what I am doing wrong?