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.
my code:
var array =[];
for(var i = 0 ; i< latitude.length; i++){
client.query("SELECT value->>'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);
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..
})!