title: How to iterate numbers 001 002 ... with javascript
body: <p>How to iterate numbers 001 002 ... 010 011 012 ... 100 101 102... with javascript?
  I tried as following, it works wen num is over 100, however num under 100, it doesn't work.
  Please teach me better way.</p>
  
  <hr>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Pages&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;script language="JavaScript"&gt;
  
  document.write('&lt;table width="650"&gt;&lt;tr&gt;&lt;td&gt;');
      num = 123; 
      var i, j, k = num;
      numlen = num.length; 
  
      if (numlen == 1 ) {
          for (var i=1; (i&lt;num); i++) { 
          document.write('00'+i+' ');
          }
      }
      else if (numlen == 2) {
          for (var i=1; (i&lt;10); i++) {
          document.write('00'+i+' ');
          }
          for (var i=10; (i&lt;=num); i++) {
          document.write('0'+i+' ');
          }
      }
      else {
          for (var i=1; (i&lt;10); i++) {
          document.write('00'+i+' ');
          }
          for (var i=10; (i&lt;100); i++) {
          document.write('0'+i+' ');
          }
          for (var i=100; (i&lt;=num); i++) {
          document.write(i+' ');
          }
      }
  document.write('&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;');
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <h2>    </h2>