title: How to loop through a list of static values (constants) in JavaScript?
body: <p>How to loop through a fixed (development time) list of values in JavaScript?</p>
  
  <p>In Perl, I'd do:</p>
  
  <pre><code>for my $item ('foo', 'bar', 'baz') {
  </code></pre>
  
  <p>which would run the loop with <code>foo</code>, <code>bar</code> and <code>baz</code> in <code>$item</code> (one each loop run).</p>
  
  <p>JavaScript could do:</p>
  
  <pre><code>for (item in new Array('foo', 'bar', 'baz')) {
  </code></pre>
  
  <p>but that would make <code>item</code> contain <code>0</code>, <code>1</code> and <code>2</code>, not the values.</p>
  
  <p>Copy&amp;paste the source for each item would be an option, but a very bad one in terms of maintenance.</p>
  
  <p>Another option would be</p>
  
  <pre><code>var items = new Array('foo', 'bar', 'baz');
  for (i in items) {
      var item = items[i];
  </code></pre>
  
  <p>But that's also bad code as it defines a structure (Array) with lots of overhead where none is needed.</p>