title: How to finish the loop to insert data into an array before populating the JSON in nodeJs
body: <p>I like to fill all the data from my loop into my array but the problem is the loop is executed lastly. I try to print the data but the array is always empty.</p>
  <pre><code>var data = new Array();
          for (let station of table) {
              request.query('SELECT TOP (1) CONVERT(varchar, Date_Time, 120) Date_Time FROM '+station+' ORDER BY Date_Time DESC', function (err, req) {
                  if (err) throw err;
                  date_time = req.recordset.map(el=&gt;el.Date_Time)[0];
                  var i = data.push({&quot;date_time&quot;:date_time,&quot;station_name&quot;:name[table.indexOf(station)]});
                  console.log(i);
              });
          }
          let json_data = JSON.stringify({&quot;data&quot;:data});
          res.writeHead(200, {'Content-Type': 'text/html'});
          res.write(json_data);
          res.end();
  </code></pre>