The Array class has a method called from that can be used to create a two-dimensional array. This method takes anything iterable and creates a new array from it.
For our use-case we can just pass it in array and it will go through each element, and create a new array from it.
JAVASCRIPT
const i = 3;
const j = 3;
const array = Array.from({ length: i }, () =>Array(j));
console.log(array);
This is a very sleek way to create a two-dimensional array because it's in one line and doesn't require any loops.
Array.map
The final way to create a two-dimensional array is to use the Array.map method. This method takes an array or anything iterable, and iterates over it one by one, running a function on each element and replacing the element with the output.
In our case, we just want to create a new array every time it gets to a new element in the original array.
We can also use the fill() function to initialize our array with a value.