I wish to retrieve hall and its length from the result. Unfortunately, I am not able to retrieve it out and it shows undefined.
These are data:
{
"result": {
"Hall 0": [
{
"lectureID": "1110000001",
"startTime": "08:30:00",
"endTime": "10:30:00"
},
{
"lectureID": "1110000002",
"startTime": "12:30:00",
"endTime": "14:00:00"
},
{
"lectureID": "1110000004",
"startTime": "14:00:00",
"endTime": "16:00:00"
}
],
"Hall 1": [
{
"lectureID": "1110000003",
"startTime": "08:00:00",
"endTime": "09:00:00"
}
],
"Hall 2": [
{
"lectureID": "1110000006",
"startTime": "09:00:00",
"endTime": "11:00:00"
}
],
"Hall 3": [
{
"lectureID": "1110000007",
"startTime": "08:30:00",
"endTime": "11:00:00"
}
]
These are my codes to retrieve the elements in Hall and the hall.length :
for (let i = 0; i < Object.keys(result).length; i++) {
console.log("result: ",result[`Hall ${i}`]); //this line shows undefined
console.log(result[`Hall ${i}`].length); //this line is undefined
for (let j = 0; j < result[`Hall ${i}`].length; j++) {
const lecture = result[`Hall ${i}`][j];
const startTime = lecture.startTime;
const endTime = lecture.endtime;
earliestStartTime = Math.min(earliestStartTime, startTime);
latestEndTime = Math.max(latestEndTime, endTime);
}
}
May I know how can I get the objects in result as well as the elements in Hall? Thank you so much!
resulthere? In provided json (which is incorrect) all the "Halls" are under "result" entry. If you assign the whole object to "result" variable then you need to use "result.result" to access your objectsconsole.log(JSON.stringify(obj, null, 2)), then copy and paste the data into the question. Highlight it and click the{}button in the toolbar.resulthere is a{}computed from API