0

I need to count numbers from 1 - 999 using three digits output.

Here is what i need:

001
002
003
004
005
006
007 
008
009
010
011
  .
  .
  .
099
100
  .
  .
  .
999

Is this possible using javascript or jQuery? Many Thanks.

user2631534
  • 467
  • 4
  • 9
  • 27

1 Answers1

7

Yes, just print the numbers from 1-999 with padded zeroes at the beginning when needed.

for(var i = 1; i <= 999; i++) {
   console.log(("00" + i).slice(-3));
}

You can see this in action on this jsFiddle demo.

Peter Olson
  • 139,199
  • 49
  • 202
  • 242
  • woow..that's was quick..this is what i need...i was searching for javascript command but i now learn that is slice. Many Thanks. – user2631534 Jan 09 '14 at 19:17