0

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.

asked Jan 3, 2023 at 19:05
1
  • 3
    You’re trying to access 'd' IN 'tzOffset' - but it's not there, but in other d. I mean event['start']['d']['d']. Commented Jan 3, 2023 at 19:08

3 Answers 3

2

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']);
answered Jan 3, 2023 at 19:09

Comments

0

You can access the d from event['start']['d']['d']), Because tzOffset doesn't have any value to access.

answered Jan 4, 2023 at 10:22

Comments

-1
alert(event['title'] + event['start']['d'])

It seems that there is no key "d" in "tzOffset",because it is null.

answered Jan 3, 2023 at 19:08

1 Comment

A code-only answer is not high quality. While this code may be useful, you can improve it by saying why it works, how it works, when it should be used, and what its limitations are. Please edit your answer to include explanation and link to relevant documentation.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.