One Liner

Create 2D array

const generateArray = (n) => Array(n).fill(0).map(_ => Array(n).fill(0));

Example

generateArray(3); //  [[0,0,0],[0,0,0],[0,0,0]]
Last Update: 05:54 - 19 April 2024

On this page