title: Why isn't my array being populated in an HTTP request callback function?
body: <pre><code>var dataGet = [];
  
  var data = JSON.stringify(false);
  
  for (i = 0; i &lt; 5; i++) {
  
    var XMLHttpRequest = require(&quot;xmlhttprequest&quot;).XMLHttpRequest;
    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;
  
    xhr.addEventListener(&quot;readystatechange&quot;, function() {
      if (this.readyState === this.DONE) {
        var name = this.responseText;
        var n = name.search(&quot;my_var&quot;);
        var IL = name.substr(n + 17, 4);
        IL = IL.replace(/\D/g, '');
        IL = parseInt(IL, 10);
        dataGet.push([174 + i, IL]);
      }
    });
  
    var url = &quot;my_url&quot;.concat(174 + i).concat(&quot;my_url_suffix&quot;);
  
    xhr.open(&quot;GET&quot;, url);
    xhr.setRequestHeader(&quot;accept&quot;, &quot;application/json&quot;);
    xhr.setRequestHeader(&quot;content-type&quot;, &quot;application/json&quot;);
    xhr.setRequestHeader(&quot;x-auth-token&quot;, &quot;my_auth_token&quot;);
  
    xhr.send(data);
  }
  
  for (i = 0; i &lt; 5; i++) {
    console.log(dataGet[i, 0]);
  }
  </code></pre>
  <p>I'm trying to fill up dataGet with the data I pull from the website. It just spits out five lines of &quot;undefined&quot;. If I use console.log within the if statement, it'll spit out the correct values. How do I put those values in a data construct other than console.log? I'm using node.js with XMLHTTPRequest - and I have no idea how any of this works.</p>
  <p>Thanks in advance
  -A complete newb</p>