当前代码
priceHistory是具有对象的对象。
Object {
"2020-05-17 10:43:45": Object {
"created_at": "2020-06-17 10:43:45",
"price": 1000,
},
"2020-05-17 10:43:51": Object {
"created_at": "2020-07-17 10:43:51",
"price": 2000,
},
"2020-05-17 10:43:56": Object {
"created_at": "2020-08-17 10:43:56",
"price": 3000,
},
"2020-05-17 10:44:01": Object {
"created_at": "2020-09-17 10:44:01",
"price": 4000,
},
}
Object.keys(priceHistory).forEach((history) => {
console.log(priceHistory[history]);
});
问题
When using forEach for priceHistory, console.log(priceHistory[history]);
outputs
Object {
"created_at": "2020-07-17 10:43:51",
"price": 2000,
}
Object {
"created_at": "2020-08-17 10:43:56",
"price": 3000,
}
Object {
"created_at": "2020-09-17 10:44:01",
"price": 4000,
}
Object {
"created_at": "2020-06-17 10:43:45",
"price": 1000,
}
对象的顺序已更改。 你怎么解决呢? created_at是字符串,price是数字。
如果您能给我任何建议,我将不胜感激。