Javascript delete object property not working

后端 未结 5 1758
难免孤独
难免孤独 2021-01-01 13:31

I\'m running some project on MEAN.js and I\'ve got a following problem. I want to make some user\'s profile calculation and the save it to database. But there\'s a problem w

5条回答
  •  猫巷女王i
    2021-01-01 14:21

    The answer above from Majed A is the simplest solution that works for single objects properties, we can even make it for more easier by removing the ...user spreader. just delete the property from your object._doc sub-object. in your example it would have been:

    user.save()
    delete user._doc.password
    res.status(201).json(user) // The password will not be shown in JSON but it has been saved.
    

提交回复
热议问题