"accessing nested objects"

can you tell me why this solution wouldnt work?

  **Your code so far**

const myStorage = {
"car": {
  "inside": {
    "glove box": "maps",
    "passenger seat": "crumbs"
   },
  "outside": {
    "trunk": "jack"
  }
}
};

const gloveBoxContents = myStorage.car["inside"].glovebox;
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55

Challenge: Accessing Nested Objects

Link to the challenge:

Blockquote

Because the dot-notation is reserved for attributes and methods.
You have to use the bracket-notation to access keys and values - and thus the nested objects.

Main reason is, you cannot even properly write it. As you see it’s “glove box” but you wrote .glovebox seemingly noticing that you canot put a whitespace into the command but obviously if you don’t write the correct string, how is JS supposed to know what you want to do? It’s certainly not trying out adding/removing whitespaces.

You can use the . dot notation if the key is a single word like (inside), but if you have the key i.e., two or more words then you have to use the bracket notation [ ] and a quote inside it to specify two or more words
e g…[“you got this”].

1 Like