I am facing an issue with my code where the keys are not always consistently named.
When I try to use key numbers instead, the code stops working.
Here is the object I am dealing with:
{
"timestamp": 1622844000,
"datetime": "2021-06-05 00:00:00",
"COMBINED COUNT": [ -3, 0, 3, -109 ]
}
This is the code I have written to read the data and populate a Google chart:
success: function(obj) {
for (var i = 0; i < obj.length; i++) {
var temp = [JSON.stringify(obj[i]["datetime"]).substr(11,6) , Number(JSON.stringify(obj[i]["COMBINED COUNT"][0])) , "blue"];
chartdata.push(temp);
}
The output looks like this:
00:00,-3,blue,
However, when I try to change 'datetime' to 1 and 'COMBINED COUNT' to 2, the code doesn't produce any result.
success: function(obj) {
for (var i = 0; i < obj.length; i++) {
var temp = [JSON.stringify(obj[i][1]).substr(11,6) , Number(JSON.stringify(obj[i][2][0])) , "blue"];
chartdata.push(temp);
}
Can anyone explain why this happens? And what should I do in order to access the correct key values?
Thank you in advance!