title: Why is my code not awaiting in a forEach when it works when I use a for loop?
body: <p>I have a following code which creates remote folders locally if they do not exist:</p>
  
  <pre><code>await remoteFolders
    .filter(rf =&gt; !localFolders.some(lf =&gt; lf === rf))
    .forEach(async (rf) =&gt; await this.createFolder(rf));
  </code></pre>
  
  <p>Method createFolder looks like this:</p>
  
  <pre><code>async createFolder(folderPath) {
    if (!(await fs.exists(folderPath))) {
      await fs.mkdir(folderPath);
    }
  }
  </code></pre>
  
  <p>The problem is that if I debug I can see that await in forEach is ignored and the loop does not wait until createFolder method finishes. So if I create directories which depend on previous ones, it obviously fails.</p>
  
  <p>But if I use for-loop it works fine (await is taken into account and loop execution continues after createFolder finishes):</p>
  
  <pre><code>for (let i = 0; i &lt; remoteFolders.length; i++) {
    if (!localFolders.some(lf =&gt; lf === remoteFolders[i])) {
      await this.createFolder(remoteFolders[i]);
    }
  }
  </code></pre>
  
  <p>I can use this one, but using forEach looks more elegant to me. Why does not forEach take await into account?</p>