Last active
December 9, 2017 23:41
-
-
Save Nicknyr/50a3b7fa539884971fe17472c9d9ae97 to your computer and use it in GitHub Desktop.
Javascript: Looping over an array and calling a function in a sychronous manner using setInterval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// loop over the array using the iteratee function at the specified interval | |
function intervalForEach(array, iteratee, delay) { | |
let current = 0 | |
let interval = setInterval(() => { | |
if (current === array.length) { | |
clearInterval(interval) | |
} else { | |
iteratee(array[current]) | |
current++ | |
} | |
}, delay) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment