I'm currently facing an issue with a JavaScript variable that I am trying to initialize within another function using a for
loop:
var test = {
det: [{x: -1, y: -1}]
};
for (var i = 0; i < 4; i++) {
test.det.push({x:10+i, y:10});
}
console.log(test.det);
Despite my efforts, when I attempt to access test.det[0]
, I still see -1 & -1
as the values โโof x & y
. The first set of values pushed remain at index 1. It appears there is a shift in all indices but the reason behind this behavior eludes me.