Javascript “Variable Variables”: how to assign variable based on another variable?

Looks like an array to me, or am I missing something?

var counters = [0,0,0];

function process(index) {
   ++counters[index]; 
      /* or ++counters[index]+index, not sure what you want to do */
   if (counters[index] === 13) { 
      /* do stuff */ 
   }
}

Leave a Comment