Search Results

Search found 1 results on 1 pages for 'user3094292'.

Page 1/1 | 1 

  • Add new element in existing object

    - by user3094292
    I am using node.js. I have to add new elements in the object before to send a response to client. user.getMatch(req.user, function(err, match){ for( k=0; k<match.length; k++){ var userId = { id : match[k].match_id }; var user = new User(userId); console.log('k: ' + k); user.getUserInfo(function(err2, info){ console.log('k here: ' + k); if(info){ match[k].foo = info[0].foo; } }); } var response = { data : match }; res.json(response); }); I want to add an element "foo" from user.getUserInfo to the object "match" that was returned by user.getMatch. And then send all the data as response to the client. But it got an error because "k" inside of user.getUserInfo is not equal to the "k" outside. I do not know why the both "k" are not equal. And how will I send a response to the client after performing the loop. Thanks for your help!

    Read the article

1