title: What are the Alternatives to eval in JavaScript?
body: <p>I have a little bit of code that looks just like this:</p>
  
  <pre><code>function StrippedExample(i1, i2, i3, i4, i5, i6, i7, i8) {
      this.i = [];
      for (var i=1,j=0 ;i&lt;9;i++) {
          var k = eval("i"+i);
          if (k &gt; 0) {
              this.i[j++] = k;
          }
      }
  }
  </code></pre>
  
  <p>FireBug profiler claims that second longest function is eval(), taking up to nearly 6% of the run time.</p>
  
  <p><a href="https://stackoverflow.com/questions/86513/why-is-using-javascript-eval-function-a-bad-idea">Everyone says eval is EVIL</a> (as in bad) and slow (as I have found), but I can't really do anything else - the server simply pulls the data out the database and pushes to the browser.</p>
  
  <p><strong>What alternatives do I have?</strong> I could do the same as I am doing here on the server but that just shifts the burden higher up the chain. I can't change the database layout since everything hooks into those 8 variables and is a massive undertaking.</p>