1

In ReactJS I have used Fetch() to get https://query2.finance.yahoo.com/v8/finance/chart/M6E=F and am now trying to access the nested item that is stored in the json object called "actualData". Due to it using "0" in the path, I cannot find a way to drill down in the following line...

console.log(actualData.chart.result.0.meta.currency);

The code above errors because of the "0". How do I include that "0" to access the "currency" element under "meta"?

mdkb
  • 372
  • 1
  • 14
  • 2
    result is a array so `actualData.chart.result[0].meta.currency` – iamhuynq Jul 13 '22 at 11:37
  • 1
    you are right. thank you. I tried a lot of methods in this https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json but missed the fact it was telling me it was an array. if you want to post that as an answer I can close this. – mdkb Jul 13 '22 at 11:43

2 Answers2

1

Try it with this: console.log(actualData.chart.result[0].meta.currency);

Martin
  • 628
  • 1
  • 9
  • 28
1

the result is a array, so you should access data by index

actualData.chart.result[0].meta.currency
iamhuynq
  • 5,357
  • 1
  • 13
  • 36