Skip to content

Instantly share code, notes, and snippets.

@solimanware
Created September 30, 2018 12:03
Show Gist options
  • Save solimanware/2afd0e3e3338e29dc899350f281ba07d to your computer and use it in GitHub Desktop.
Save solimanware/2afd0e3e3338e29dc899350f281ba07d to your computer and use it in GitHub Desktop.
How To Make 2D Array In JavaScript
/**
* @param {number} rows
* @param {number} cols
*/
function make2DArray(rows, cols) {
let x = [];
for (let i = 0; i < rows; i++) {
x[i] = [];
for (let j = 0; j < cols; j++) {
x[i][j] = [];
}
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment