There is no wait command in Javascript. The way to get this behavior is using setTimeout :
for (var i=0; i<8; i++){ do_something(i); } function do_something(j) { setTimeout(function() { tasks to do; }, 2000 * j); }
Each time the do_something() function is called, it performs the "tasks to be completed" scheduled for 2000*i milliseconds.
source share