Q:

Initializing the 2D array elements in javascript

I want to initialize and then print the elements of a 2D array using javascript.
I wrote this code but nothing displays as output. How to output this array?
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(mat[i][j]);
  }
  document.writeln("<br />");
}

A:

<html>
    <body>
    </body>
    <script>
        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(mat[i][j]);
            }

            document.writeln("<br />");
        }
    </script>
</html>
   

