Thomas2
12-09-2003, 12:13 PM
I am having problems with using two-dimensional arrays. Assigning values to it apparently works OK, but referencing the array later repeats only the values of the last column for each column (if you run the script below, it should print out the same sequence twice, but only the first (from the assignment loop) is correct).
<html>
<body>
<SCRIPT Language="Javascript" type="text/javascript">
<!--
var arr=new Array();
for (i=0; i<=2; i++) {
for (j=0; j<=1; j++) {
arr[i,j]=i+j;
document.write(arr[i,j]);
}
}
document.write(' ');
for (i=0; i<=2; i++) {
for (j=0; j<=1; j++) {
document.write(arr[i,j]);
}
}
//-->
</SCRIPT>
</body>
</html>
<html>
<body>
<SCRIPT Language="Javascript" type="text/javascript">
<!--
var arr=new Array();
for (i=0; i<=2; i++) {
for (j=0; j<=1; j++) {
arr[i,j]=i+j;
document.write(arr[i,j]);
}
}
document.write(' ');
for (i=0; i<=2; i++) {
for (j=0; j<=1; j++) {
document.write(arr[i,j]);
}
}
//-->
</SCRIPT>
</body>
</html>