title: Returning an array of promises for Promise.all using filter not working
body: <p>I have an array of objects and for each I execute a promise. Then, if all resolve, I expect to get a <code>.then</code> call in <code>Promise.all</code>. Problem is that with the following example I only get the output </p>
  
  <blockquote>
    <p>All done in approach 2</p>
  </blockquote>
  
  <p>I think the following code is pretty much explanatory but, in a nutshell, what I'm doing is:</p>
  
  <ol>
  <li>Declare 3 objects as <code>vals</code> and I want to create a promise based on each.</li>
  <li>Approach 1: use <code>vals.map</code> to get an array of promises based on <code>vals</code></li>
  <li>Approach 2: iterate through <code>vals</code> using a <code>for</code> and push a new promise in each iteration.</li>
  </ol>
  
  <p>What's wrong with this code and why is it working only for approach 2?</p>
  
  <pre><code>#!/usr/bin/env node
  
  let vals = [
      {
          name: "name1"
      },
      {
          name: "name2"
      },
      {
          name: "name3"
      }
  ];
  
  function newPromise(obj) {
      return new Promise((resolve) =&gt; Promise.resolve(obj.name))
  }
  
  /**
   * Approach 1: use .map function to get an array of promises
   */
  
  let promises = vals.map((item) =&gt; newPromise(item));
  Promise.all(promises)
      .then(() =&gt; console.log("All done in approach 1"))
      .catch(() =&gt; console.log("Error in approach 1"));
  
  /**
   * Approach 2: iterate through vals using a for an push a new promise for the promises array
   */
  
  let promises2 = [];
  for (let i = 0 ; i &lt; vals.length; i++) {
      promises.push(newPromise(vals[i]));
  }
  Promise.all(promises2)
      .then(() =&gt; console.log("All done in approach 2"))
      .catch(() =&gt; console.log("Error in approach 2"));
  </code></pre>
  
  <p>I'm using node 8.9.1 with ES6 (native Promises).</p>