I have a javascript object called event which is output from the console.log below:
{
"title": "Test Title",
"location": "Test Location",
"isAllday": false,
"isPrivate": false,
"state": "Busy",
"start": {
"tzOffset": null,
"d": {
"d": "2023年01月03日T16:00:00.000Z"
}
},
"end": {
"tzOffset": null,
"d": {
"d": "2023年01月03日T16:30:00.000Z"
}
},
"id": "afdb82fd-fddd-58ce-bd0b-ab0beb2bce7b"
}
I can access some items through alert(event['title'] + event['location']);
I cannot access the nested items like start.tzOffset.d
If I try alert(event['title'] + event['start']['tzOffset']['d']);
I get an error "Uncaught TypeError: Cannot read properties of null (reading 'd')"
Any help greatly appreciated.
-
3You’re trying to access 'd' IN 'tzOffset' - but it's not there, but in other d. I mean event['start']['d']['d'].sashok1337– sashok13372023年01月03日 19:08:15 +00:00Commented Jan 3, 2023 at 19:08
3 Answers 3
That's because tzOffset
doesn't have a nested key called d
inside of it.
instead it is inside start
object and inside d
object there is a key called d
so it needs to be like this:
alert(event['title'] + event['start']['d']['d']);
Comments
You can access the d
from event['start']['d']['d'])
, Because tzOffset doesn't have any value to access.
Comments
alert(event['title'] + event['start']['d'])
It seems that there is no key "d" in "tzOffset",because it is null.