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*

18
  • 7
    impressed you managed to phrase my question better than I could, you are indeed correct as on reflection all I need is an array of numbers that I can later loop through :) Thanks for your answer. Commented Sep 19, 2010 at 18:08
  • 202
    @Godders: If this is what you're looking for, why do you need an array? A simple var n = 45; and then looping from 1..n would do. Commented Sep 19, 2010 at 18:33
  • 4
    @Godders - To note, if you want to decrease the size of the array after it is created to length M, simply use foo.length = M --- The cut off info is lost. See it in action ==> jsfiddle.net/ACMXp Commented Sep 20, 2010 at 2:11
  • 35
    I really dont get why this answer even have upvotes... especially when the OP himself agrees it doesn't make any sense in a few comments above since he could just have done var n = 45;. Commented Nov 4, 2013 at 14:39
  • 113
    @scunliffe: Please note, that new Array(45); does not "create a 45 element array" (in same meaning as [undefined,undefined,..undefined] does). It rather "creates empty array with length = 45" ([undefined x 45]), same as var foo = []; foo.length=45;. That's why forEach, and map will not apply in this case. Commented Jan 24, 2014 at 14:00