I'm facing an issue with my JavaScript code. I have 4 three-dimensional arrays, each of size 500x500x220. To optimize performance, I defined a single array and then created the other four arrays from it. However, when I modify one array, it affects the others as well. Here is how my code looks:
<script type="text/javascript">
var content = new Array();
var signs = new Array();
var sens = new Array();
var props = new Array();
var ini = new Array();
for(i = 0; i < 500; i++){
ini[i] = new Array();
for(j = 0; j < 500; j++){
ini[i][j] = new Array();
}
}
content = ini;
signs = ini;
sens = ini;
props = ini;
function f(){
alert(signs[3][3][2]); //Returns undefined
content[3][3][2] = 2;
alert(signs[3][3][2]); //Returns 2
}
f();
</script>
Even though the f()
function is meant to only modify the content
array, it ends up affecting the signs
array as well. Can anyone explain why this happens and suggest a workaround?
Just so you know, I am using HTA.