title: Javascript "Variable Variables": how to assign variable based on another variable?
body: <p>I have a set of global counter variables in Javascript:</p>
  
  <pre><code>var counter_0 = 0;
  var counter_1 = 0;
  var counter_2 = 0;
  </code></pre>
  
  <p>etc</p>
  
  <p>I then have a Javascript function that accepts an 'index' number that maps to those global counters. Inside this function, I need to read and write to those global counters using the 'index' value passed to the function.</p>
  
  <p>Example of how I'd like it to work, but of course doesn't work at all:</p>
  
  <pre><code>function process(index) {
      // do some processing
  
      // if 'index' == 0, then this would be incrementing the counter_0 global variable
      ++counter_+index; 
  
      if (counter_+index == 13)
      {
          // do other stuff
      }
  }
  </code></pre>
  
  <p>I hope what I'm trying to accomplish is clear. If not I'll try to clarify. Thanks.</p>
  
  <p>EDIT Clarification:</p>
  
  <p>I'm not trying to increment the name of the counter, but rather the value the counter contains.</p>