1

I'm using node (express) and want to add a new property before my response (in here I named it as result) get passed to the front-end.

async.parallel(stack, function (err,result) {
  result.users[0].price = 100
  // console.log(result.users[0]); // I couldn't find price property here I wonder why.
  res.json(result);
});

Why is this so?

I tried to alter the other property like password:

console.log(delete result.users[0].password);
console.log(result.users[0]) // password is still present here?

I tried a mini example in fiddle it worked. https://jsfiddle.net/16333z15/

Eugene Mihaylin
  • 1,736
  • 3
  • 16
  • 31
Jessica Illy
  • 67
  • 1
  • 2
  • 7

1 Answers1

0
router.get('/json', function (req, res) {
    var result = {
        users: [{
            id: 1,
            name: "abc"
        }]
    };
    result.users[0].price = 100;
    res.json(result);
});

I have tried this in express and it's worked. You should check the result type, I think it's not tuple.

Jared Chu
  • 2,757
  • 4
  • 27
  • 38
  • 1
    I found the problem is using async, damn it this npm behave strangely, it doesn't give me the power to alter the response. – Jessica Illy Oct 16 '16 at 14:05