Update 3d matrix with coordinates in javascript
<p>I'm trying to create a 3d matrix in javascript, and then I want to update its values by using its coordinates:</p>

<pre><code>var xAxis = [];
var yAxis = [];
var ZAxis = [];
var dimensions = 4;

//initalize matrix

for (var i=0;i&lt;dimensions;i++){
    xAxis.push(0);
}
for (var j=0;j&lt;dimensions;j++){
    yAxis.push(xAxis);
}
for (var k=0;k&lt;dimensions;k++){
    matrix.push(yAxis);
}

//check value of one point in the matrix
matrix[1][2][3]; //returns 0 as expected
//update value of matrix using same coordinates
matrix[1][2][3] = 2;
</code></pre>

<p>When I run the last step, it will not only update my expected <a href="https://i.stack.imgur.com/FO4GP.jpg" rel="nofollow noreferrer">1</a>[2][3] coordinates, but it also updates every third value of every array to 2 as you will see in the image:
<a href="https://i.stack.imgur.com/FO4GP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FO4GP.jpg" alt="enter image description here"></a></p>

<p>How can I manage to update only the value that I want?? I mean, the number 2 should only be in one coordinate point, in this case <a href="https://i.stack.imgur.com/FO4GP.jpg" rel="nofollow noreferrer">1</a>[2][3].</p>

<p><strong>Note:</strong>
I think it's got something to do that it might be assigning the original arrays into the matrix instead of new copies of themselves, so when I update one coordinate, I'm actually updating the original array, and the other arrays are just pointing at the original, so that's why it's been reflected there as well?</p>