This program outprints first 0
then 189
. I know that its due to javascripts executing this asynchronously. What would be the correct way to make both logs output 189
? Without getting into callback hell?
roaming = [];
connection.query("SELECT land FROM roaming", function (err, res) {
if (err) {
console.log("Error: " + err);
} else {
res.forEach(function(entry){
roaming.push(entry.land);
});
console.log(roaming.length);
}
});
console.log(roaming.length);