I'm newer in javascript and trying to execute async function inside loop. Anyone can explain why loop continuous executing after printing "all done" here is my code
function asynchFunc(n, loop) {
setTimeout(loop, n);
}
function processItems(items, cb) {
(function loop (index) {
if (index == items.length) return cb();
console.log(items[index]);
asynchFunc(items[index], loop);
loop(++index);
}(0));
}
processItems([1000,2000,3000,4000,5000], function(ret){
console.log('all done');
});