I have the following JavaScript code
let logs = [];
for (let j = 0; j < 10; j++) {
logs[j] = { j };
console.log('logs', logs);
}
I expect the output to be as follows
logs [ { j: 0 } ]
logs [ { j: 0 }, { j: 1 } ]
logs [ { j: 0 }, { j: 1 }, { j: 2 } ]
logs [ { j: 0 }, { j: 1 }, { j: 2 }, { j: 3 } ]
logs [ { j: 0 }, { j: 1 }, { j: 2 }, { j: 3 }, { j: 4 } ]
logs [ { j: 0 }, { j: 1 }, { j: 2 }, { j: 3 }, { j: 4 }, { j: 5 } ]...
And this is what I get when I run this code in the nodejs console.
But when I check in browser, I get the following output
logs [ { j: 0 },
{ j: 1 },
{ j: 2 },
{ j: 3 },
{ j: 4 },
{ j: 5 },
{ j: 6 },
{ j: 7 },
{ j: 8 },
{ j: 9 } ]
for every iteration