Skip to content

Instantly share code, notes, and snippets.

@ChinmayMoghe
Last active March 1, 2025 17:48
Show Gist options
  • Save ChinmayMoghe/cbd769863b9cb72fbde57814226a1596 to your computer and use it in GitHub Desktop.
Save ChinmayMoghe/cbd769863b9cb72fbde57814226a1596 to your computer and use it in GitHub Desktop.
create an 2d array and fill it with something
// Just a utility function I thought of you could use it for some graph problem, or if you are building a board state for minesweeper
// or for whatever you need.....
function create2DArray(n,fillWith) {
return Array.from({length:n},()=>Array.from({length:n},()=>fillWith));
}
// Usage create2DArray(2,0)
/*
[
[0,0],
[0,0]
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment