title: How to identify Loop is completed
body: <p>I want to minimize following code. Working in <strong>node js</strong></p>
  
  <pre><code>var each = 0;
  var final = {};
  // myLoop have some array values;
  myLoop.forEach(function(row) {
  
      //data retrive from db
      db.query('SELECT * FROM test where type=?',[row.type], function(err, result) {
          final[each] = result;
          each++;
          if (each == myLoop.length) {
             return final;
          }
      });
  
  });
  </code></pre>
  
  <p>Above code working fine, but trying to avoid <strong>if (each == myLoop.length)</strong> condition.
  Is anything available to identify the loop is completed?</p>
  
  <p>Is possible something like below:</p>
  
  <pre><code>myLoop.forEach(function(row) {
      //do needs
  }).done({
      return final;
  });
  </code></pre>