I have a template object that I am recursively modifying and needing to push into an array like so
var base = {
a: 600,
b: 1.15,
c: 0,
d: 200,
e: 3,
f: 3,
g: 1,
h: 1,
}
var array2 = new Array();
for(var i=1;i<=3;i++){
base.a = base.a*12
base.b = base.b-0.01
base.d = base.d*4
base.e = Math.ceil(base.e * 1.5)
base.f = base.e
array2.push(base)
}
The expected output would be
[ { a: 7200, b: 1.13, c: 0, d: 800, e: 5, f: 5, g: 1, h: 1 },
{ a: 86400, b: 1.12, c: 0, d: 3200, e: 8, f: 8, g: 1, h: 1 } ]
Actual is
[ { a: 86400, b: 1.11, c: 0, d: 3200, e: 8, f: 8, g: 1, h: 1 },
{ a: 86400, b: 1.11, c: 0, d: 3200, e: 8, f: 8, g: 1, h: 1 } ]
And I am finding that when I manipulate the object, it recursively changes the values for each time the object was placed in the array.
So the question is, how can I place new objects into this array in a fashion that I do not retroactively change all values when recursively updating the base template.
(Edited a value that was incorrect by 0.01 in the expected output [1].b)