Using promise function inside Javascript Array map : <p>Having an array of objects [obj1, obj2]</p>

<p>I want to use Map function to make a DB query (that uses promises) about all of them and attach the results of the query to each object.</p>

<pre><code>[obj1, obj2].map(function(obj){
  db.query('obj1.id').then(function(results){
     obj1.rows = results
     return obj1
  })
})
</code></pre>

<p>Of course this doesn't work and the output array is [undefined, undefined]</p>

<p>What's the best way of solving a problem like this? I don't mind using other libraries like async</p>
