title: How to run a for loop for promises in node.js
body: <p>I have a function that returns a promise. The promise actually reads a JSON file and pushes some data of that file in an array and returns that array. I am able to do it with a single file but I want to run a for loop with multiple file paths and want all the results (resolve) of each promise to be pushed into an array. What's the correct way of doing it?</p>
  
  <p>In the following code directoryName is a result of a promise. This is basically an array of directory names. In the secondMethod function I am using just the first directory name from the array to operate on a file inside that directory. Assume each directory in the array will have the t.json file. </p>
  
  <pre><code>let secondMethod = function(directoryName) {
      let promise = new Promise(function(resolve, reject) {
          let tJsonPath = path.join(directoryPath, directoryName[0], 't.json')
          jsonfile.readFile(tJsonPath, function(err, obj) {
              let infoRow = []
              infoRow.push(obj.name, obj.description, obj.license);
              resolve(infoRow)
          })
      }
      );
      return promise;
  }
  </code></pre>
  
  <p>How can I run a loop on the directoryName array so that jsonfile.readFile is executed for each element of the array and the result of it can be stored in a global array? </p>