Created
December 25, 2022 05:30
-
-
Save thmain/34f61c5fe3b4cc3437ec334a599e3879 to your computer and use it in GitHub Desktop.
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
var input = [{ | |
'name': 'event1', | |
'time': 1000 | |
}, { | |
'name': 'event2', | |
'time': 2000 | |
}, { | |
'name': 'event3', | |
'time': 3000 | |
}]; | |
var i = 0; | |
var inputLength = input.length; | |
function iterate() { | |
if (i < inputLength) { | |
var currentElement = input[i]; | |
console.log(`${currentElement.name} Started.`); | |
setTimeout( function () { | |
console.log(`${currentElement.name} Ended.`); | |
iterate(); | |
}, currentElement.time); | |
} | |
i++; | |
} | |
iterate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment