Answer the question
In order to leave comments, you need to log in
How to stop iterating over an array in neo-async?
There is an array [10, 50, 100, 358]
When iterating, when we meet the value 100, we need to stop the enumeration. How to do it in neo-async (Module)?
var tempArr = [10, 50, 100, 358];
async.eachSeries(tempArr, function(val, index, done){
console.log('[Перебор массива tempArr] Итерация #' + index);
if(val == 100) {
console.log('Нашли нужное значение в массиве! Index = ' + index);
done(); // Вот здесь нужно вызвать break, но как это сделать в neo-async?
}
else done();
});
var tempArr = [3, 5];
var tempArr2 = [10, 50, 100, 358, 400];
async.eachSeries(tempArr, function(val, index, done){
console.log('\n -> [Перебор массива tempArr] Итерация #' + index);
async.eachSeries(tempArr2, function(val2, index2, done2){
console.log('[Перебор массива tempArr2] Итерация #' + index2);
if(val2 == 100) {
console.log('Нашли нужное значение в массиве! Index = ' + index2);
done2({'break': true}); // Fake Error
}
else done2();
}, done);
},
function(){
console.log('\n Перебор массив `tempArr` завершен.');
});
-> [Iteration of the array tempArr] Iteration #0
[Iteration of the array tempArr2] Iteration #0
[Iteration of the array tempArr2] Iteration #1
[Iteration of the array tempArr2] Iteration #2
Found the desired value in the array! Index = 2
Iterating over the `tempArr` array is complete.
Answer the question
In order to leave comments, you need to log in
I don't know what neo-async is, but in all javascript it's always been like this:
var tempArr = [10, 50, 100, 358];
async.eachSeries(tempArr, function(val, index, done){
console.log('[Перебор массива tempArr] Итерация #' + index);
if(val == 100) {
console.log('Нашли нужное значение в массиве! Index = ' + index);
return false;
}
else done();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question