title: How do I log responses in the correct order using Async code
body: <p>I need to create a function that runs a 'getFile' function on each item in an array. The getFile function logs 'File contents of x' x being whatever element is in the array. </p>
  
  <p>Currently, I have a working function that runs the getFile on the array and waits for the final response before logging the results.</p>
  
  <p>However, I now need to log the responses as I receive them in order. For example, if my array is [1, 2, 3, 4, 5] currently it logs 'File contents of x' in a random order, so if it was to return the logs, 3 then 4 then 1. As soon as I receive 1, I need to log that, then once I receive 2 logs that and so on.</p>
  
  <p>I will insert my current code below. The problem I'm having is I need to know when the 'empty space' in my array becomes populated so I can log it in real time. Therefore allowing my user to see the result build up rather than just having to wait until all the responses have come back</p>
  
  <pre><code>function fetchContentOfFiles(fileNames, testCB) {
    const fileContent = [];
    let counter = 0;
  
    fileNames.forEach((file, i) =&gt; {
      getFile(file, (err, fileName) =&gt; {
        if (err) console.log(err)
        else {
          fileContent[i] = fileName;
          counter++
          if (counter === fileNames.length) {
            testCB(null, fileContent)
          };
          console.log(fileContent)
        };
      });
    });
  };
  </code></pre>