如何 select 在 vanillajs 中 json 中对象的对象的字段?

How to select a field from object of objects inside json in vanillajs?

只是想知道,我怎样才能以下列格式遍历我的 json 对象?

[
  {"page":1,"pages":1,"per_page":"600","total":264},
  [
    {
      "indicator":
     {"id":"NY.GDP.MKTP.CD","value":"GDP (current US$)"},
      "country":{"id":"1A","value":"ArabWorld"},
      "value":"2565871160292.11","decimal":"0","date":"2015"
    },
    {
      "indicator":
      {"id":"NY.GDP.MKTP.CD","value":"GDP (current US$)"},
      "country":{"id":"S3","value":"Caribbean small states"},
      "value":"66935278418.3676","decimal":"0","date":"2015"
    },
    {
      "indicator":
      {"id":"NY.GDP.MKTP.CD","value":"GDP (current US$)"},
      "country":{"id":"B8","value":"Central Europe and the Baltics"},
      "value":"1281495024762.4","decimal":"0","date":"2015"
    }
  ]
]

我有这个方法returns json 对象

countries: function() {
const URL = 'http://api.worldbank.org/countries/all/indicators/NY.GDP.MKTP.CD?date=2015:2015&per_page=600&format=json'
let countries = []
fetch(URL).then(i => i.json()).then(j => countries.push(...j))
console.log(countries);
}

例如,我如何才能 select date 字段?

谢谢 -B

到 select 嵌套很深的东西,比如你会访问它的日期字段 >

 countries[1][0].date

其中第二个索引 [0] 可以是您在数据数组上的任何索引。

用你的数据检查here