首页 > 解决方案 > 如何从 JavaScript 中的对象内部获取对象?

问题描述

我在从 REST API 返回的对象中有对象,如下所示:

const json = { 
"0": {
"barcode": "897382173",
"img": "-",
"name": "Lemon",
"productId": "DC-PR111113"
},

 "1": {
"barcode": "697382173",
"img": "-",
"name": "Aloe",
"productId": "DC-PR111113"}
}

开头和结尾都有花括号

我需要把那些对象(0和1)拿出来,像这样放在数组中

const json = [
"0": {
"barcode": "897382173",
"img": "-",
"name": "Lemon",
"productId": "DC-PR111113"
},


 "1": {
"barcode": "697382173",
"img": "-",
"name": "Aloe",
"productId": "DC-PR111113"}
}
]

我尝试了很多东西,但仍然没有运气:(

标签: javascriptarraysobjectelementcurly-braces

解决方案


推荐阅读