Skip to content

Instantly share code, notes, and snippets.

@NaClYen
Created December 10, 2021 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaClYen/a314215cbcb02a7a562a68f8b7d988c0 to your computer and use it in GitHub Desktop.
Save NaClYen/a314215cbcb02a7a562a68f8b7d988c0 to your computer and use it in GitHub Desktop.
javascript create array without for-loop
// [1, 1, 1, 1, 1]
[...new Array(5)].map(() => 1)
// [0, 1, 2, 3, 4]
[...new Array(5)].map((_, index) => index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment