title: How do I directly assign values to an array but use push method on OOB exception?
body: <p>It is my understanding that -- from a performance perspective -- direct assignment is more desirable than <code>.push()</code> when populating an array.</p>
  
  <p>My code is currently as follows:</p>
  
  <pre><code>for each (var e in Collection) {
    do {
      DB_Query().forEach(function(e){data.push([e.title,e.id])});
    } while (pageToken);
  }
  </code></pre>
  
  <p><code>DB_Query()</code> method runs a Google Drive query and returns a list.</p>
  
  <p>My issue arises because <code>DB_Query()</code> can return a list of variable length. As such, if I construct <code>data = new Array(100)</code>, direct assignment has the potential to go out of bounds.</p>
  
  <p>Is there a method by which I could <code>try</code> and <code>catch</code> an Out of Bounds exception to have values directly assigned for the 100 pre-allocated indices, but use <code>.push()</code> for any overflow? The expectation here is that an OOB exception will not occur often.</p>
  
  <p>Also, I'm not sure if it matters, but I am clearing the array after a counter variable is <code>&gt;=100</code> using the following method:</p>
  
  <pre><code>while(data.length &gt; 0) {data.pop()}
  </code></pre>