Is there a nice one liner for a range array in javascript, equivalent to python's list(range(m, n))? ES6 permitted. Here's the best I've come up with so far:
[x for(x of (function*(){for(let i=0;i<100;i++) yield i})())]
You can use Array.from and arrow functions for a better readability:
Array.from({length: 4}, (_, n) => n) // = [0, 1, 2, 3]
Array.from({length: 5}, (_, n) => n+6) // = [6, 7, 8, 9, 10]
Array.from({length: 6}, (_, n) => n-3) // = [-3, -2, -1, 0, 1, 2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With