Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 141
    Just a note, this will always start at 0. Will need to chain a map to the array to adjust the values ([...Array(10).keys()].map(x => x++);) to start at 1 Commented Dec 29, 2015 at 21:42
  • 84
    Just change map(x => x++) to map(x => ++x) due to precedence increment happens after the value return :) Commented Feb 12, 2016 at 9:39
  • 202
    Er what!? Why map when you can simply slice? [...Array(N+1).keys()].slice(1) Commented Apr 24, 2016 at 19:51
  • 38
    Or don't use keys and only 1 map -> Array.from(Array(10)).map((e,i)=>i+1) Commented Jun 29, 2016 at 14:03
  • 136
    Or don't use keys and map and just pass a mapping function to from Array.from(Array(10), (e,i)=>i+1) Commented Feb 21, 2017 at 13:10