Can't access object property, even though it shows up in a console log

后端 未结 30 2087
日久生厌
日久生厌 2020-11-22 06:26

Below, you can see the output from these two logs. The first clearly shows the full object with the property I\'m trying to access, but on the very next line of code, I can\

30条回答
  •  逝去的感伤
    2020-11-22 06:53

    If this is an issue occurring when working with Mongoose, the following may happen:

    console.log(object)
    

    returns everything, including the desired key.

    console.log(object.key)
    

    returns undefined.

    If that is happening, it means that the key is missing from the Mongoose Schema. Adding it in will resolve the issue.

提交回复
热议问题