I am currently trying to access the values of an object that is within an array which is inside another object. The data is structured as follows:
[{
"id": "99a4e6ef-68b0-4cdc-8f2f-d0337290a9be",
"stock_name": "Just Energy Group, Inc.",
"shareholders": [{
"userId": "e9328bb2-81ac-4e86-9ec8-520b1909cc9b",
"number_of_shares": 266
}, {
"userId": "d42ff6a6-9b2f-4561-ac2e-0cf2bb170430",
"number_of_shares": 389
}]
}]
The following is the code I am using to retrieve data from GitHub using axios and display the user ID:
const axios = require('axios')
require("util").inspect.defaultOptions.depth = null;
async function getStocks(){
const { data } = await axios.get('https://gist.githubusercontent.com/graffixnyc/8c363d85e61863ac044097c0d199dbcc/raw/7d79752a9342ac97e4953bce23db0388a39642bf/stocks.json')
return data // this will be the array of people objects
}
async function listShareholders() {
let c=[]
let a = await getStocks();
for(i=0;i<a.length;i++){
for(j=0;j<a[i].shareholders;j++)
c.push((a[i].shareholders[j].userId))
}
return c
}
async function bc(){
const address = await listShareholders()
console.log(address)
}
bc()
I am unsure why I am not getting any output.