title: Console.log shows array but can't be returned
body: <p>I'm new to working with promises (I'm using 'co' in node) so I'm not entirely sure what's failing with this code:</p>
  
  <pre><code>function* excelToJSON(excelFileNames) {
    var jsonData = [];
  
    for (let index = 0; index &lt; excelFileNames.length; index++) {
      parseXlsx(excelFilesNames[index], function (err, data) {
  
        jsonData.push(data);
        console.log(jsonData); //***Shows data correctly
      });
    }
  
    console.log(jsonData); //***Empty array
    return yield jsonData;
  }
  </code></pre>
  
  <p>It reads the file, converts it and, at least within the loop, it shows everything correctly, but once we get out of the loop the data seems to disappear. I've also tried to return one of the values from within the loop but that doesn't work either.</p>
  
  <p>EDIT:
  parseXlsx is from the 'excel' module here: <a href="https://github.com/trevordixon/excel.js" rel="nofollow noreferrer">https://github.com/trevordixon/excel.js</a>
  I'm not entirely sure if it's async or sync, to be honest. This seems to be its code, and I know 'extractFiles' returns a promise but since it then goes through 'parseXlsx' I'm not sure what happens afterwards:</p>
  
  <pre><code>function parseXlsx(path, sheet, cb) {
    if (typeof cb === 'undefined') {
      cb = sheet;
      sheet = '1';
    }
    extractFiles(path, sheet).then(function(files) {
      cb(null, extractData(files));
    },
    function(err) {
      cb(err);
    });
  };
  </code></pre>
  
  <p>EDIT2:
  What I used to solve it is a combination of several answers, thanks to all of you.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function* excelToJSON(excelFileNames) {
    return new Promise(function(resolve, reject) {
      var jsonData = [];
  
      if (excelFilesNames === null || excelFilesNames.length === 0) {
        reject();
      }
  
      for (let index = 0; index &lt; excelFilesNames.length; index++) {
        parseXlsx(excelFilesNames[index], function(err, data) {
          if (err) {
            throw err;
          }
  
          jsonData.push(data);
  
          if (jsonData.length === excelFilesNames.length) {
            resolve(jsonData);
          }
        });
      }
    });
  }</code></pre>
  </div>
  </div>
  </p>