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

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

I have an object like this

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


        
7条回答
  •  旧时难觅i
    2021-01-17 08:01

    If you have loaded this object into records, both records.Name = "test" or records['Name'] = "test" will work. You have either not loaded the object correctly, or are inserting an undefined value into it.

    To test: add console.log(records.userId), this should print 'test' to the terminal.

    Also add console.log(name). If you get ReferenceError: name is not defined, you obviously cannot do: records.Name = name

提交回复
热议问题