Javascript Array Multidimensional array initialize
let array1 = [ [ 1, 2, 3 ], // first row [ 4, 5, 6 ] ]; // second row let array2 = [ [ 1, 2 ], // first row [ 3 ], // second row [ 4, 5, 6 ] ]; // third row outputArray( "Values in array1 by row", array1 ); outputArray( "Values in array2 by row", array2 ); function outputArray( heading, theArray ) { console.log(heading);//w w w . jav a 2 s . co m // iterates through the set of one-dimensional arrays for ( let i in theArray ) { // iterates through the elements of each one-dimensional // array for ( let j in theArray[ i ] ) console.log( theArray[ i ][ j ] + " " ); } }