title: javascript Promise.all returns last promise only
body: <p>I have a script like:</p>
  
  <pre><code>var a = [{'a': 1},{'b': 2}]
  var allPromises = new Array(a.length)
  for(var i in a) {
      allPromises[i] = Promise.resolve().then(response =&gt; {
        console.log(i)
        console.log(a[i])
        // Do somethig on every loop with key and value
        return i
      })
  }
  
  Promise.all(allPromises).then(response =&gt; console.log(response))
  </code></pre>
  
  <p>Here in my <code>for loop</code> it only gives me last index and value of last index while I want the value on every loop and perform some action with key and value.. But I am getting the last key and value only..</p>
  
  <p>I tried getting the value on <code>Promise.all</code>'s response but didnt work.</p>
  
  <p>How can I get the index of my array on <code>allPromises</code>'s response ? </p>
  
  <p>I can do it by makeing a counter. But when I again call the function the counter is reset so I donnt want to use the counter. </p>
  
  <p>Is there anyway I can get index on every loop for promise ?</p>