Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • I believe this is useful when the array of numbers is being used for data that cannot be processed at the receiving end. (Like an HTML template that is just replacing values.) Commented Aug 22, 2012 at 15:01
  • 6
    Like I said, I need to populate a dropdown with the numbers 1 through 10. That's all. There IS a usecase, MY usecase. That's how I found this page. So just building an array by hand was less complicated than anything I saw here. So my requirements aren't the requirements of the OP. But I have my answer. Commented Oct 24, 2018 at 11:24
  • 1
    @vol7ron There is a usecase, I also have one. In angular, in paging, I want to show the pages in the footer that are clickable. So I loop the elements in a view with *ngFor="let p of pagesCounter". You have a better solution for that? BTW, check out stackoverflow.com/questions/36354325/… Commented Mar 30, 2019 at 8:47
  • 1
    This is wrong. All examples produce array of form [0,..,n-1] whereas question is for [1,...,n] Commented Feb 27, 2020 at 13:18
  • 1
    @husayt yes, you’re right; however, that’s the point of the answer (as with the selected answer) to store the number from 0..N and display from 1..N+1, by adding 1 in the presentation Commented Feb 27, 2020 at 13:45