title: Node js(sails.js) for loop sending data to view before loop is completed
body: <p>I'm fairly new to node.js and sails.js but not to javascript I have a simple function that iterates over an array of abjects, validates them, each validated object in the array is pushed into another array with i want to pass onto my my view.</p>
  
  <pre><code>if(results){
      var items = results.one;
      var toReturn = [];
      for(var i = 0; i&lt;items.length; i++){
          var item = items[i];
          Inventory.findOne({primaryKey: item.primaryKey}, function(err, found){
              if(err){
                  res.send("Err reached");
              }
              else{
                  //Some validation code
  
                  if (validations_failed_condition){
                      console.log("FAiled validations");
                  }
                  else{
                      console.log("Validations passed, Pushing item");
                      console.log(item);
                      toReturn.push(item);
                  }
              }
          });
      }
      res.send(toReturn);
  }
  </code></pre>
  
  <p>Even though my logs are showing me multiple items are being validated and being pushed into my array toReturn. The data being sent to the view is an empty array.</p>
  
  <p>Is for looping in node.js asynchronous ? Is data being passed to the view before the for loop is completed ?</p>
  
  <p>What can I do to fix this ? </p>