referencing the same object inside another callback from forEach
<p>I'm trying to add a new property to an object. It seems that it works correctly from this scope:</p>

<pre><code>rows.forEach(function (row, i) {
  row.foo = i;
});
</code></pre>

<p>If I do console.log(rows) I can see that foo was added with the correct value. If I have another callback within the forEach, I don't see the change any more. Why?</p>

<pre><code>rows.forEach(function (row, i) {
  getUserById(row.user_id, function(user) {           
    row.foo = i;
  });
});
</code></pre>

<p>Yes, the callback get's fired correctly. Here is the getUserById</p>

<pre><code>function getUserById(userId, callback) {
  connection.query('select * from t_user where id = ?', [userId], function(err, results) {

  if (err) {
    console.log("repo error");
  } else {
    if (results.length == 0) {
      callback(null);
  } else {
      callback(results[0]);
    }
  }
});
</code></pre>

<p>}</p>
