How do we initialize and create new multi dimension array?
Let's imagine if I want to initialize a 4x4 multi dimension array and fill it with 0's
Ideally, in 2D arrays, we would do
let oned_array = new Array(10).fill(0); // would create array of size 10 and fill it up with 0
How would I do something like [[0,0], [0,0]] (2x2 matrix)
let matrix = new Array([]).fill(0);
I'm trying to solve few algorithm problems and this requires me creating a new multi dimension array and going through them (Island problem etc)
Please advise.
EDIT:
Another solution I found:
Array(2).fill(0).map(_ => Array(2).fill(0));
[a-zA-z][a-zA-Z0-9_]+1Darraythat is starting with a non alpha character. most of the languages will give you error