我希望在foreach
完成后执行回调,但它没有正常工作。我该怎么做?
var response = [];
myArray.forEach(function(data) {
data.asyncFunction(function(result) {
response.push(result);
});
}, function() {
console.log(response); // Not being called.
});
console.log(response); // (Empty) Executed before foreach finish.
forEach
中执行任何异步操作吗? - thefourtheye