Answer the question
In order to leave comments, you need to log in
How to use callback in a loop?
qw = getSpisocHesh11_20(chatId);
console.log(qw);
for(var ere=0;ere<qw.length;ere++) {
console.log(qw[ere] + " в for");
getSpisocRating2(msg, qw[ere], function (spisocHESh) {
ll++;
console.log("Начало");
console.log(qw[ere]);
console.log(sendSP);
if (spisocHESh == true) {
console.log('Добавилось1 ' + qw[ere]);
sendSP.push(qw[ere]);
}
if (ll == qw.length) {
console.log(sendSP);
setSpisocHesh11_20(chatId, sendSP);
sendMessage(msg, sendSP.join('\n'));
}
})
}
Answer the question
In order to leave comments, you need to log in
Here the context changes, you will have to bind each callback to its own context, it's easier to
use instead of for
qw.forEach(function(item, ere){
// тут qw[ere] или item
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question