title: Javascript - Declare variables with a for loop
body: <p>I'm just wondering if it's possible to declare multiple variables using a <code>for loop</code> in Javascript. </p>
  
  <p><strong>Example:</strong> I have 4 <code>&lt;article&gt;</code> elements whose Ids are <code>article1</code> <code>article2</code> <code>article3</code> and <code>article4</code>. Instead of declaring each variable independently, I'd like to do it in a loop (as they use essentially the same code and I don't want to repeat myself!). </p>
  
  <p>Something like:</p>
  
  <pre><code>window.ready = function(){
      for (var i=1; i&lt;=4; i++){
  
              var article[i] = document.getElementById("article" + i);
  
          }
  }
  </code></pre>
  
  <p>The above returns an error with an unexpected <code>[</code>, so my syntax must be off (I'm very new to JS), but <strong>(a) is this on the right track</strong> and <strong>(b) will these be global variables if I run them in a window.ready function?</strong></p>