I am running a function which returns json data:
const stocks = await response.json();
let stocksData = stocks.values;
If I print out the result gives a result as:
0 : {datetime: '2023-01-18', open: '1.07940', high: '1.08870', low: '1.07670', close: '1.07970'}
1 : {datetime: '2023-01-19', open: '1.07945', high: '1.08365', low: '1.07820', close: '1.08300'}
2 : {datetime: '2023-01-20', open: '1.08300', high: '1.08585', low: '1.08020', close: '1.08530'}
3 : {datetime: '2023-01-23', open: '1.08595', high: '1.09270', low: '1.0
I am trying to get values as: open, high, low, close with below line of code:
var open = stocksData["open"];
and print:
console.log("Open: " + open);
I get result:
Open: undefined
I thought its because stocksData is an object and tried to change it to a string and try to access the value again as follows:
var b = JSON.parse(JSON.stringify(stocksData));
var high = b["high"];
console.log("High: " + high);
I still get:
High: undefined
And there where I am stuck now, where am I getting it wrong?