Add a new attribute to existing json object in node.js

后端 未结 7 1762
梦如初夏
梦如初夏 2021-01-17 07:16

I have an object like this

==================records=========={ Id: 5114a3c21203e0d811000088,
  userId: \'test\',
  sUserId: test,
  userName: \'test\',
  ur         


        
7条回答
  •  时光说笑
    2021-01-17 07:58

    Just use,

    var convertedJSON = JSON.parse(JSON.stringify(mongooseReturnedDocument);
    

    and Then,

    convertedJSON.newProperty = 'Hello!' 
    

    'Hello!' can be anything, a number, a object or JSON Object Literal.

    Cheers! :)

提交回复
热议问题