I am attempting to access the most recent element in the Time Series (5 min)
object without specifying the date/time after running this JavaScript code:
var getStock = new XMLHttpRequest();
getStock.open("GET","https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=IBM&interval=5min&apikey=demo", false);
getStock.send(null);
var current_stock = JSON.parse(getStock.responseText);
console.log(current_stock);
var current_stock_price = current_stock["Time Series (5min)"][0]["4. close"];
In this instance (refer to screenshot), I am looking at Time Series (5 min)
> 2022-04-21 20:00:00
-> 4. close
, but I am encountering an undefined error.
Even when trying it in the developer console with the complete JSON file, using
current_stock["Time Series (5 min)"]
displays all child values in the console. However, appending [0]
or ["2022-04-21 20:00:00"]
at the end results in an undefined error.