简体   繁体   English

如何遍历javascript中的深度嵌套对象数组?

[英]How can I iterate through array of deeply nested objects in javascript?

How can I iterate through an array of deeply nested objects in javascript?如何在 javascript 中遍历一组深度嵌套的对象? I would like to iterate through results array of objects.我想遍历结果对象数组。
Something like this:像这样的东西:

{
      "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
        ]

Considering this is your object, you could easily employ forEach() or map() to iterate through objects inside the results array, depending on your need.考虑到这是您的对象,您可以轻松地使用forEach()map()来遍历results数组中的对象,具体取决于您的需要。

Here's a screenshot as an example:下面以截图为例:

Code代码

I hope it helped you!我希望它对你有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM