Answer the question
In order to leave comments, you need to log in
Why doesn't iterate over the entire array?
var arr = [];
arr[0] = 'sda21g';
arr[5] = 'g42c';
arr[8] = '09-sdq3';
arr[10] = 'm/xndhi';
console.log(arr);
async.each(arr, function(el, callback){
console.log('----------------------------');
console.log(el);
console.log('----------------------------');
callback();
},
function(err) {
console.log('Прошли все элементы массива arr');
});
Answer the question
In order to leave comments, you need to log in
Async will call the final callback only when all iterations of the array have passed, where the number of iterations for it is the length of the array. According to the JS specification, the length of the array is the index of the last element + 1. In the example, a sparse array is specified, and async uses Array.forEach to iterate, which skips missing indices, respectively, the final callback will never be called.
To get out of this situation, you can (optionally) :
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question