How can I wait for the for loop to go to next loop?
How can I make sure that the userdetails is executed and realresult.playername is assigned to the new variable before passing it on ?
code:
return new Promise( function (resolve, reject) {
arr = [];
messages.find({convid: convid}).then(function(result) {
for(var a in result) {
realresult = result[a];
userData.userDetails(realresult.userid).then(function (result) {
realresult.playername = result.username;
});
userData.usercashinfo(realresult.userid).then(function (resulttwo) {
realresult.playerdetails = resulttwo;
});
arr.push(realresult);
}
return resolve(arr);
});
});