我不想获取数组中每个对象的 ID。
我有这个数组
[
{
"-ML8Lx8jOSv64Ecat611": {
"category": "Automotive Parts & Accessories",
"description": "I will be there at least but I don't know if I can help in any way I can",
"item": "Apple Watch",
"price": "429,99",
"timestamp": "2020-11-02T21:28:11+07:00",
"viewCount": 0
}
}
]
我期望得到的是
[
{
"category": "Automotive Parts & Accessories",
"description": "I will be there at least but I don't know if I can help in any way I can",
"item": "Apple Watch",
"price": "429,99",
"timestamp": "2020-11-02T21:28:11+07:00",
"viewCount": 0
}
]
由于您想要在输出中的对象是嵌套的,您需要在 JSON 中循环两个级别:
let input = [
{
"-ML8Lx8jOSv64Ecat611": {
"category": "Automotive Parts & Accessories",
"description": "I will be there at least but I don't know if I can help in any way I can",
"item": "Apple Watch",
"price": "429,99",
"timestamp": "2020-11-02T21:28:11+07:00",
"viewCount": 0
}
}
];
let result = []
input.forEach(obj => {
Object.keys(obj).forEach(key => {
result.push(obj[key]);
});
});
console.log(result);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句