title: JS - how to use setTimeout function inside of the for loop?
body: <p>I have created the following simple script to push buttons on the website...</p>
  <pre><code>var b = document.querySelectorAll('.button'), count;
  for(var count = 0; count &lt; b.length; count++) {
  b[count].click();
  }
  </code></pre>
  <p>...and it's working but I wanted to build the setTimeout function into it, so the buttons are not pushed all at once but with delay (either fixed or random) after each iteration.</p>
  <p>The most logical seemed to be the code below...</p>
  <pre><code>var b = document.querySelectorAll('.button'), count;
  for(var count = 0; count &lt; b.length; count++) {
  setTimeout(function() {
  b[count].click();
  }, 2000);
  }
  </code></pre>
  <p>...but it's not working at all. Is the setTimeout in the wrong place ? It's inside of the loop so I expected it to be ok... Plis advise.</p>