Two-dimensional array work around : Multi Dimensional Array « Array « JavaScript Tutorial






<HTML>
<HEAD>
<TITLE>
Two-dimensional array work around
</TITLE>
<HEAD>
   <BODY>
   <SCRIPT>
    var matrix = new Array(4);
    matrix[0] = new Array(4);
    matrix[1] = new Array(4);
    matrix[2] = new Array(4);
    matrix[3] = new Array(4);

    matrix[0][0] = "A1";
    matrix[0][1] = "A2";
    matrix[0][2] = "A3";
    matrix[0][3] = "A4";
    
    matrix[1][0] = "B1";
    matrix[1][1] = "B2";
    matrix[1][3] = "B3";

    matrix[2][0] = "C1";
    matrix[2][1] = "C2";
    matrix[2][3] = "C3";


    matrix[3][0] = "D1";
    matrix[3][1] = "D2";
    matrix[3][3] = "D3";

    for (var i = 0; i < matrix.length; i++){
     for (var j = 0; j < matrix.length; j++){
        document.write ("Element (" + i + ", " + j + ") is " + matrix[i][j] + " -- ");
       }
       document.write("<br>");
    }
   </SCRIPT>
   </BODY>
</HTML>








11.6.Multi Dimensional Array
11.6.1.Multi-dimensional array
11.6.2.Two-dimensional array work around