DEV Community

Discussion on: How to create range in Javascript

Collapse
 
jprando profile image
Jeudi Prando • Edited
/// declaration
(s,e)=>[...Array(e-s+1)].map((_,i)=>s+i)
/// use
((s,e)=>[...Array(e-s+1)].map((_,i)=>s+i))(5,9)
/// output
[5, 6, 7, 8, 9]
Enter fullscreen mode Exit fullscreen mode

😉🤩✨✨✨

Collapse
 
keithpjolley profile image
keith p. jolley

☝️ is what i was looking for. tweaked it slightly:

((e, s=0, d=1)=>[...Array(e-s)].map((_,i)=>(s+i)*d))(5,0,1/4)
[0, 0.25, 0.5, 0.75, 1]
Enter fullscreen mode Exit fullscreen mode