title: Javascript loop through array asynchronous
body: <p>I'm making a bot code for a game running on NodeJS and what this function is supposed to do is to loop through an array of vectors and then make the bot go to each vector.</p>
  
  <p>However, what it's actually doing is telling the bot to run to all the vectors at the same time so it spazzes out and then runs to the last vector in the array:</p>
  
  <pre><code>function digSchedule() {
      var arrayLength = blocksToMine.length;
      for (var i = 0; i &lt; blocksToMine.length; i++) {
          console.log(i);
          scaffoldTo(blocksToMine[i]);
      }
      ...
  }
  </code></pre>
  
  <p>The function <code>scaffoldTo()</code> needs to be ran and then wait for the bot to do said function then run it for the next element in the array, but I can't figure out how to do it.</p>