Why do i not get a 3d array in javascript when i use nester for loops?

21 Views Asked by At

I am trying to log a 3D array to the console in javascript, then clone it, and log the clone. If this is the only code I write, it works perfectly fine. But once I start to process the cloned 3D array within a 4x nested for loop even after I've logged both of them, they start to break. They no longer display 3D arrays in the console. They display as 1d arrays of length 64. Surely, what I do here on line 4 should never affect the output of line 3. Is this an issue with my code, with chrome, or with javascript?

`function thetaStep(state) {

console.log(state);
let temporaryState = state;

for (let x = 0; x < 5; x++) {
    for (let y = 0; y < 5; y++) {         
        for (let z = 0; z < 64; z++) {
            temporaryState[x, y, z] = state[x, y, z]
            for (let c = 0; c < 5; c++) {
                temporaryState[x, y, z] = temporaryState[x, y, z] ^ state[(x - 1) % 5, c, z] ^ state[(x + 1) % 5, c, z + 1];
            }
        }
    }
}

return temporaryState;

}`

I should clarify that "state" is a 3D array, where each item in the innermost array is a 1 or a 0.

When this nested for loop is in my code, the state prints incorrectly, but when i remove it, it works.

How should I fix this issue?

0

There are 0 best solutions below