提问人:tg8 提问时间:1/26/2020 最后编辑:Brian Tompsett - 汤莱恩tg8 更新时间:11/18/2023 访问量:132
如何在 javascript 中遍历深度嵌套对象的数组?
How can I iterate through array of deeply nested objects in javascript?
问:
如何在 JavaScript 中遍历深度嵌套对象的数组?我想遍历对象的结果数组。
像这样的东西:
{
"meta": {
"disclaimer": "Do not rely on openFDA to make decisions
regarding medical care. While we make every effort to
ensure that data is accurate, you should assume all results are
unvalidated. We may limit or otherwise restrict your access to
the API in line with our Terms of Service.",
"terms": "https://open.fda.gov/terms/",
"license": "https://open.fda.gov/license/",
"last_updated": "2019-12-14",
"results": {
"skip": 0,
"limit": 1,
"total": 504
}
},
**"results": [**
{
"effective_time": "20190502",
"inactive_ingredient": [
"Inactive ingredients D&C yellow #10, FD&C yellow #6
]
答:
-1赞
devegili
1/26/2020
#1
考虑到这是您的对象,您可以根据需要轻松地使用或遍历数组中的对象。forEach()
map()
results
下面是一个屏幕截图作为示例:
希望对您有所帮助!
评论
1赞
menaka_
1/26/2020
添加一些代码结果会很有帮助。
0赞
tg8
1/28/2020
我是这样迭代的: {drugs.map(drug => ( <div key={drug.id}> <li><h5>生效日期</h5> {drug.effective_time}</li> <li><h5>通用名称</h5> {drug.openfda.generic_name}</li> <li><h5>品牌名称</h5> {drug.openfda.brand_name}</li>))}
评论