I am currently developing using Javascript and I came over a problem, I couldn't solve. I would say that I am very experienced in programming, but something like this never happened before and I couldn't fix it using friends or the internet.
In the code below I create a simple 2D array and fill every position with 0.1. Then I log the array, modify it and log it again. What would you expect to be the output? I would expect it to log an array filled with many 0.1s and log another array filled with many 0.1s and at position 1,2 it should be 100.
But the real outcome are two similar arrays. It gets even weirder when I comment the line out, where I edit the array. Then the output arrays are again the same, but without the modification. So the first log depends on code executed AFTER it. And that seems very very weird to me. I'va also tried putting the modificaction line in an 1 second timeout. Same results.
Thanks for help in advance.
let test = [];
for (let xx = 0; xx < 2; xx++) {
test.push([]);
for (let yy = 0; yy < 6; yy++) {
test[xx].push(0.1);
}
}
console.log(test);
test[1][2] = 100;
console.log(test);