I have an arrays=[John; Alex; Mark], I wanna to show the elements of this array one by one by 3 second delay.
s=[John; Alex; Mark]
for (var i=0; i<=3; i++) {
Try
var s=['John', 'Alex', 'Mark']; var x = document.getElementById('x'); function display(i){ if(i >= s.length){ i = 0; } x.innerHTML = s[i]; setTimeout(function(){ display(i + 1) }, 2000) } display(0)
Demo: Fiddle