title: Google Script: forEach to Array
body: <p>I'm trying to push the returned values from forEach to an array. </p>
  
  <p>Right now results are returned individually in the Logger like</p>
  
  <p><code>result 1
   result 2</code></p>
  
  <p>That's what I want, I just don't know how to get those results back to a single array that I can use outside of the <code>forEach</code> function (as this function is part of a larger one). </p>
  
  <p>Any tips? I looked <a href="https://stackoverflow.com/questions/12491101/javascript-create-array-from-for-loop">HERE</a> and attempted to work from that below. The other results I found here were about PHP, which I don't understand. </p>
  
  <pre><code>urls.forEach(function(urlTest) {
      var htmls = UrlFetchApp.fetch(urlTest).getContentText();
      var reg = /text1boldblack\"\&gt;U(.*?)\&lt;\/div/g;
      var reg2 = /text1boldblack\"\&gt;|\&lt;\/div/g;
      var extract = htmls.match(reg);
      var string = String(extract);
      var listDivName = string.replace(/text1boldblack\"\&gt;|\&lt;\/div/g,'');
  
      var array = [];
      for (var i = 0; i &lt; listDivName.length; ++i) {
      array.push(i);
      Logger.log(array);
      }
  </code></pre>
  
  <p>Below is an example of what <code>Logger.log(array);</code> currently returns which is obviously more than the two results I was expecting. </p>
  
  <pre><code>[18-12-30 17:05:13:597 EST] U09 Girls 1 - Fall 2018
  [18-12-30 17:05:13:597 EST] [0.0]
  [18-12-30 17:05:13:598 EST] [0.0, 1.0]
  [18-12-30 17:05:13:599 EST] [0.0, 1.0, 2.0]
  [18-12-30 17:05:13:599 EST] [0.0, 1.0, 2.0, 3.0]
  [18-12-30 17:05:13:600 EST] [0.0, 1.0, 2.0, 3.0, 4.0]
  [18-12-30 17:05:13:600 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
  [18-12-30 17:05:13:601 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
  [18-12-30 17:05:13:602 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
  [18-12-30 17:05:13:602 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
  [18-12-30 17:05:13:603 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
  [18-12-30 17:05:13:604 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
  [18-12-30 17:05:13:604 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]
  [18-12-30 17:05:13:605 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
  [18-12-30 17:05:13:606 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0]
  [18-12-30 17:05:13:606 EST] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0]
  </code></pre>