var cb = [];
for (var i = 0; i < 10; i++) {
cb.push({
'test': 'value'
});
console.log(cb);
};
I'm expecting to get: [{test: value}, {test: value}, ... , {test: value}]
What I end up getting is the final result at every log statement:
[Object]
[Object, Object]
[Object, Object, Object]
[Object, Object, Object, Object]
[Object, Object, Object, Object, Object]
[Object, Object, Object, Object, Object]
[Object, Object, Object, Object, Object, Object]
..........
When I expand any of those arrays they all have the same result. For example, the first array contains:
[{test: value}, {test: value}, ... , {test: value}]
which is the final value, shouldn't it just have 1 object? The final result is what I expect, but I'm just confused about why after the first push the array has 10 elements. Can someone please explain what's going on?