multidimentiional array javascript

Solutions on MaxInterview for multidimentiional array javascript by the best coders in the world

showing results for - "multidimentiional array javascript"
Davide
02 Aug 2020
1// Javascript Multidimentional Array
2
3// 1D Array
4arr = Array(3);
5console.log(arr)	// [ , ,  ]
6
7// 1D Array with Fill
8arr = Array(3).fill(2);
9console.log(arr)	// [ 2, 2, 2 ]
10
11//2D Array
12arr = Array(3).fill( Array(3) );
13console.log(arr);	// [ [ , ,  ], [ , ,  ], [ , ,  ] ]
14
15//2D Array with Fill
16arr = Array(3).fill( Array(3).fill(2) );
17console.log(arr);	// [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ] 
18
19arr = Array(3).fill( [2,2,2] );
20console.log(arr);	// [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ]