JSFiddle - React, Tailwind, and code Playground
JavaScript
function timer(myArray) {
var counter = 0;
var interval = setInterval(function() {
// There are still items we want to display
if(counter < myArray.length) {
console.log(myArray[counter]);
// We have displayed all
} else {
console.log('Finished');
clearInterval(interval);
}
// Increment counter
counter++;
}, 500); // 500 here is the interval in msec
}
var arr = ['Item 0', 'Item 1', 'Item 2', 'Item 3'];
timer(arr);