Aditya Singh Aditya Singh - 1 year ago 95
Javascript Question

How to generate range of numbers from 0 to n in ES2015 only?

I have always found the

function missing from JavaScript as it is available in python and others? Is there any concise way to generate range of numbers in ES2015 ?

EDIT: MY question is different from the mentioned duplicate as it is specific to ES2015 and not ECMASCRIPT-5. Also I need the rnage to be starting from 0 and not specific starting number (though it would be good if that is there)

Answer Source

You can use the spread operator on the keys of a freshly created array.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download