In PHP, you can do...
range(1, 3); // Array(1, 2, 3)
range("A", "C"); // Array("A", "B", "C")
That is, there is a function that lets you get a range of numbers or characters by passing the upper and lower bounds.
Is there anything built-in to JavaScript natively for this? If not, how would I implement it?
I found a JS range function equivalent to the one in PHP, and works amazingly great here. Works forward & backward, and works with integers, floats and alphabets!
And here is the minified version:
I would code something like this:
It behaves similarly to Python range:
As far as generating a numeric array for a given range, I use this:
Obviously, it won't work for alphabetical arrays.
It works for characters and numbers, going forwards or backwards with an optional step.
jsFiddle.
If augmenting native types is your thing, then assign it to
Array.range
.