let arr = [1,2,3,4,5] let index = 0 function fn(arr, cb) { console.log(index) if (index < arr.length) { index++ fn(arr, cb) } } fn(arr, function (data) { console.log(data) })