Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 25, 2022 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/34f61c5fe3b4cc3437ec334a599e3879 to your computer and use it in GitHub Desktop.
Save thmain/34f61c5fe3b4cc3437ec334a599e3879 to your computer and use it in GitHub Desktop.
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