I have a JSON array with a key that changes dynamically (room number varies each time I run the code). My goal is to access the inner JSON array using this dynamic key. Here's what I've attempted so far, but it's throwing an error.
Here is the JSON Array(data) content:
[{"6011":
[{"occupancy":"2","time":"2017-11-10 00:00:00"},
{"occupancy":"1","time":"2017-11-10 00:30:00"},
{"occupancy":"2","time":"2017-11-10 01:00:00"}]
}]
Code snippet for accessing the data:
var room = outerJSON.name;
var jsonObject = jQuery.parseJSON(JSON.stringify(data));
var innerArray = jsonObject[room]; // This line returns undefined
var innerArray2 = jsonObject.get(room); // The error "Uncaught TypeError: jsonObject.get is not a function" occurs here