Skip to content

Instantly share code, notes, and snippets.

@esundahl
Last active April 14, 2021 20:28
Show Gist options
  • Save esundahl/fb617c634005ac1dc8c0a57bbc58c82e to your computer and use it in GitHub Desktop.
Save esundahl/fb617c634005ac1dc8c0a57bbc58c82e to your computer and use it in GitHub Desktop.
Create a new array with values 0-99
// https://itnext.io/heres-why-mapping-a-constructed-array-doesn-t-work-in-javascript-f1195138615a
Array(100).map((_, i) => i) // Won't work
[...Array(100)].map((_, i) => i) // Will work
const range = (start, end) => Array.from({ length: end - start + 1 }, (x, i) => i + start)
range(0, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment