title: Asynchronous add to array in Nodejs
body: <pre><code> var veh = [];
   app.get('/updateProf', isLoggedIn, function(req, res) {
  
  
       for (var i = 0; i &lt; req.user.local.vehicles.length; i++){
             Vehicles.findById(req.user.local.vehicles[i], function(err, vehicle) {
                veh.push(vehicle);
                console.log("GET Json: " + veh);
  
              });
       }
       console.log(veh);
       res.json(veh);
       veh.length = 0;
  });
  </code></pre>
  
  <p>So I am doing a get request to obtain all my vehicles that a user owns and return its json, it works fine after a refresh, but when I go to the page it shows a empty array on the initial load, if I refresh the page, the array is populated. I think the issue is something to do with it being asynchronous but I'm having a hard time thinking this way and need some advice on how to tackle this.</p>