Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does javascript have a range function?

Hi all i was just wondering if JS has a range function which will return numbers defined in an offset. I'm not using jQuery, so pure JS would be the best solution for me.

I want to get a set of numbers in sets of 5 i.e.

  1. First set of numbers - 0 - 4
  2. Second set of numbers - 5 - 10
  3. Third set of numbers - 11 - 16
  4. And so on and so on

I was wondering if this is possible at all? I was also looking at the underscore library to see if there's any handy methods but i couldn't find anything related to this at all.

like image 710
Tunds Avatar asked Dec 07 '22 23:12

Tunds


1 Answers

If you're using ES6/2015 then you can also do this in pure JS (although, a little messy :P)

Array(5).fill().map((x,i)=>i);
like image 50
shriek Avatar answered Dec 31 '22 20:12

shriek