Created
September 30, 2018 12:03
-
-
Save solimanware/2afd0e3e3338e29dc899350f281ba07d to your computer and use it in GitHub Desktop.
How To Make 2D Array In JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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