title: node.js + for loop + query execution
body: <p>I am executing a for loop , inside that for loop i am executing an postgresql query and populating the result into an array. But i cant predict the execution  flow.</p>
  
  <p>my code:</p>
  
  <pre><code>var array =[];
         for(var i = 0 ; i&lt; latitude.length; i++){       
      client.query("SELECT value-&gt;&gt;'xxxx' as xxxx_details FROM yyyyy WHERE ST_DWithin(ST_GeogFromText('SRID=4326;POINT ("+latitude[i]+" "+longitude[i]+")'), geography(the_geom), " + radius + ")", function(err, row, fields) {               
                         array.push(row.rows[0]);
         }   
                  console.log("bbbbbbbbb=" +array);
  </code></pre>
  
  <p>What i needed is i want the array to be printed after all the query executed inside the for loop. But now its printing before the array is populated. Help me to solve this. Thanks in advance..</p>