Doen Doen - 1 year ago 67
Javascript Question

Initializing the 2D array elements in javacsript

I want to initialize and then print the eleemnts of a 2D array using javascript.
I created this code but nothing displays as output. Anyone help me to output this array? Thanks

var m = 6;
var n = 3;
var mat = new Array[m][n];

for (i = 0; i < mat.length; i++) {
for (j = 0; j < mat[i].length; j++) {
mat[i][j]) = i * j;
document.writeln("<br />");

Answer Source

        var m=6;
        var n=3;
        var mat =new Array(m);

        for( var i=0; i < m ; i++){

            mat[i] = new Array(n);

            for( var j=0;j< n ;j++){
                mat[i][j] = i*j;

            document.writeln("<br />");

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download