我有一些看似这样的承诺代码。
let residences = await DB.findAll(...);
所以我等待完成续集的承诺然后我打印一些看似承诺的东西。
console.log(residences);
[ { dataValues:
{ id: 1,
address: '6509 Pardall Rd',
city: 'Goleta',
state: 'CA',
zipcode: '93117',
user_id: 4,
category: 'apartment',
amenities: null,
created_at: Wed Mar 09 2016 22:26:09 GMT-0800 (PST),
updated_at: Wed Mar 09 2016 22:26:09 GMT-0800 (PST),
room_count: '1',
'room_types.name': 'living' },
_previousDataValues:
{ id: 1,
address: '6509 Pardall Rd',
city: 'Goleta',
state: 'CA',
zipcode: '93117',
user_id: 4,
category: 'apartment',
amenities: null,
created_at: Wed Mar 09 2016 22:26:09 GMT-0800 (PST),
updated_at: Wed Mar 09 2016 22:26:09 GMT-0800 (PST),
room_count: '1',
'room_types.name': 'living' },
_changed: {},
'$modelOptions':
{ timestamps: true,
instanceMethods: {},
classMethods: {},
validate: {},
freezeTableName: false,
underscored: true,
underscoredAll: false,
paranoid: false,
whereCollection: null,
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: [],
hooks: {},
indexes: [],
name: [Object],
omitNull: true,
sequelize: [Object],
uniqueKeys: {},
hasPrimaryKeys: true },
'$options':
{ isNewRecord: false,
'$schema': null,
'$schemaDelimiter': '',
......
但是如果我解析对象,我会得到我希望返回的承诺。
console.log(JSON.stringify(residences));
[
{
"id": 1,
"address": "6509 Pardall Rd",
"city": "Goleta",
"state": "CA",
"zipcode": "93117",
"user_id": 4,
"category": "apartment",
"amenities": null,
"created_at": "2016-03-10T06:26:09.091Z",
"updated_at": "2016-03-10T06:26:09.091Z",
"room_count": "1",
"room_types.name": "living"
}
]
为什么这两条打印线会输出如此截然不同的文字?
答案 0 :(得分:1)
console.log()
打印在您的情况下提供的对象的完整结构。但JSON.stringify()
函数忽略所有不可枚举的键。有关详细说明,请转到
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
希望它有所帮助