When I am trying to access the 0th index of the data I am getting error undefined but when I am trying to print out the whole object it is working fine. I am unable to access any element or loop over the data. The data variable works fine but the tSeries variable is undefined.
This is the code snippet:
var data;
var tSeries;
(async () => {
const response = await fetch("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=" + key);
apidata = await response.json();
data = (apidata["Meta Data"]["2. Symbol"]);
tSeries = (apidata["Time Series (Daily)"][0]);
console.log(tSeries);
})();
Here is the JSON response snippet:
{
"Meta Data": {
"1. Information": "Intraday (5min) open, high, low, close prices and volume",
"2. Symbol": "IBM",
"3. Last Refreshed": "2020-06-24 16:00:00",
"4. Interval": "5min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2020-06-24 16:00:00": {
"1. open": "116.4600",
"2. high": "116.6700",
"3. low": "116.3800",
"4. close": "116.4900",
"5. volume": "263785"
},
"2020-06-24 15:55:00": {
"1. open": "116.8000",
"2. high": "116.8600",
"3. low": "116.3500",
"4. close": "116.4700",
"5. volume": "154646"
},
"2020-06-24 15:50:00": {
"1. open": "117.0100",
"2. high": "117.1400",
"3. low": "116.8500",
"4. close": "116.8500",
"5. volume": "99465"
},
"2020-06-24 15:45:00": {
"1. open": "116.6900",
"2. high": "117.0400",
"3. low": "116.6600",
"4. close": "117.0100",
"5. volume": "83736"
}