How do we initialize and create a new multidimensional array?
Suppose I want to initialize a 4x4 multidimensional array and fill it with 0
Ideally, in 2D arrays we will do
let oned_array = new Array(10).fill(0); // create an array of size 10 and fill it with 0
How would I do something like [[0,0], [0,0]] (2x2 matrix)
let matrix = new Array([]).fill(0);
I am trying to solve several problems with algorithms, and this requires me to create a new multidimensional array and go through them (problem with an island, etc.)
Please inform.
EDIT:
Another solution I found:
Array(2).fill(0).map(_ => Array(2).fill(0));
source share