Monday 24 April 2017

javascript - Foreach callback when finish

Because forEach accept only one callback. Since you are calling asynchronous method inside forEach you need to check whether all asyn call completed



var response = [];

myArray.forEach(function(data, index) {
data.asyncFunction(function(result) {
response.push(result);
if(response.length === myArray.length) {
//foreach work done
}
});
});

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...