This is my code
for (var x in items) {
var name = items[x].Name;
var hotelID = 1;
var sql = mysql.format('INSERT INTO Item(name, hotelID) VALUES(?, ?)', [name, hotelID]);
con.query(sql, function (err, result) {
if (err) {
throw err;
}
//Below x is updated by the loop.
console.log(item[x].Name);
});
I want to get the value of x
right before the con.query() call, but here the x is updated by the for
loop before the callback is completed. How do i do that??