Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Created September 2, 2016 02:57
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 RyanCCollins/5b5e4b99be9dac4100e7c784ed3e3ddc to your computer and use it in GitHub Desktop.
Save RyanCCollins/5b5e4b99be9dac4100e7c784ed3e3ddc to your computer and use it in GitHub Desktop.
Create an array of 1 through n numbers in one line of JS

Create an array of numbers 1 to N

const N = 20;
Array.apply(null, { length: N }).map(Number.call, Number)

Another option

const arrayOfRange = (n) => Array(n).join().split(',').map((_, i) => i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment