The sub-properties of objects can be accessed by chaining together the dot or bracket notation. Here is a nested object:

Tell us what’s happening:
Describe your issue in detail here.
Slightly confused…am Iclose?

  **Your code so far**

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

var gloveBoxContents = myStorage.car["inside"].glove_box;
  **Your browser information:**

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

Challenge: Accessing Nested Objects

Link to the challenge:

Close.

But you can access the first property in the chain using dot notation – car.inside.

The second one in the chain you can’t access using dot notation, because an identifier with spaces can’t work using dot notation. To explain:

car.inside.glove box can’t work: you are saying you want the key glove on the object with the key inside on the object with the key car. And then you want to access a variable called box. So that doesn’t make sense.

And you can’t get around this by changing the name “glove box” to something else, which is what you’ve done here, that can’t possibly work. There is no property called “glove_box”

1 Like

Thanks Dan,! oh I see what you mean re space (glove key)

lol, I had an idea that glove_box wouldn’t work.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.