javascript create new 2d arrays code example
Example 1: javascript fill 2 dimensional array
const fillSquareMatrix = (size) => {
return Array(size)
.fill()
.map((u,y) => Array(size)
.fill()
.map((u,x) => y * size + x + 1));
};
console.log(fillSquareMatrix(3));
Example 2: creating 2d array in javascript
var [r, c] = [5, 5];
var m = Array(r).fill().map(()=>Array(c).fill(0));