I have a function getUserId() in that i have another function that return value from db. the result is placed in array arrUser. the array is printed in the function but not in another function. can any one give me the solution
function getUserId() {
var arrUser = new Array();
connection.query('SELECT iUserId,sFromEmailAddress FROM tblFromSenderList',function (err, results, fields) {
if (err) {
throw err;
}
if (results.length > 0) {
for (var i = 0; i< results.length ;i++){
var reader = results[i];
// console.log(reader['sFromEmailAddress']+" == " + reader['iUserId']); //ADD string - 'ID: 1'
arrUser[reader['sFromEmailAddress']] = reader['iUserId'];
}
console.log(arrUser); // prints value over here
return arrUser;
}
});
console.log(arrUser); // does not print value
}