Last active
July 9, 2023 17:33
-
-
Save Dammmien/140f45e8d6f4a2c0055e to your computer and use it in GitHub Desktop.
Easily create an empty matrix in javascript
This file contains hidden or 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
var matrix = [], | |
H = 4, // 4 rows | |
W = 6; // of 6 cells | |
for ( var y = 0; y < H; y++ ) { | |
matrix[ y ] = []; | |
for ( var x = 0; x < W; x++ ) { | |
matrix[ y ][ x ] = "foo"; | |
} | |
} | |
console.log( matrix.join('\n') ); | |
// foo,foo,foo,foo,foo,foo | |
// foo,foo,foo,foo,foo,foo | |
// foo,foo,foo,foo,foo,foo | |
// foo,foo,foo,foo,foo,foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment