javascript - How to add delay using setTimeout for every iteration? -


this question has answer here:

this creates 2 second delay , runs loop. need create 2 second delay every iteration, not once.

var myarray = ['test1','test2','test3'];  function dosettimeout(index) {   settimeout(function() { console.log(myarray[index]) }, 2000); }  var index; (index = 0; index < myarray.length; ++index) {         dosettimeout(index) } 

expected result be:

test1  (2 second delay) test2  (2 second delay) test3 

just multiply delay index

var myarray = ['test1','test2','test3'];  function dosettimeout(index) {   settimeout(function() { console.log(myarray[index]) }, index * 2000; }  var index; (index = 0; index < myarray.length; ++index) {     dosettimeout(index) } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -