Can someone explain what's going on with the output of this code?
let arr = [];
for(let i=0; i < 5; i++){
arr.push(i);
console.log(arr, i)
}
Output:
[0, 1, 2, 3, 4] 0
[0, 1, 2, 3, 4] 1
[0, 1, 2, 3, 4] 2
[0, 1, 2, 3, 4] 3
[0, 1, 2, 3, 4] 4
I'd expect it to look like:
[0] 0
[0, 1] 1
[0, 1, 2] 2
[0, 1, 2, 3] 3
[0, 1, 2, 3, 4] 4