When I run this code, all object of the array are the same.
var obj = {
a: { b: 0 }
}
var arr = [];
for(i = 0; i < 10; i++) {
arr.push(obj);
obj.a.b += 5;
}
for(i = 0; i < arr.length; i++) {
document.writeln(arr[i].a.b);
}
How can I send current values of the object to the array? Like:
[
{"a": b: 5 },
{"a": b: 10 },
{"a": b: 15 },
...
]
After Answered
I created a benchmark test for Object.assign
vs JSON.stringify
for the deep clone.