Skip to content

Instantly share code, notes, and snippets.

@isamrish
Created June 23, 2021 15:29
Show Gist options
  • Save isamrish/3fc8ab0fb97c59c6352c1da5de250ec2 to your computer and use it in GitHub Desktop.
Save isamrish/3fc8ab0fb97c59c6352c1da5de250ec2 to your computer and use it in GitHub Desktop.
JavaScript

Create an array of number (0 to n)

Array.from(Array(n+1).keys())

OR with spread operator

[...Array(n+1).keys()]

Create an array of number ( 1 to n )

Array.from({ length: n }, (_, i) => i + 1))

.... some more will come later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment