Accessing Nested Objects--Halp!

Accessing Nested Objects--Halp!
0

#1

I’m stuck. I followed the example as close as possible but I’m not sure what I’m doing wrong.

Your code so far

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

// Only change code below this line
myStorage.car.inside; // "glovebox"
var gloveBoxContents = "maps"; 

Link to the challenge:


#2

You are supposed to reference the applicable properties of the myStorage object to assign the value of “maps” to gloveBoxContents. Instead, you have just assigned the string “maps” directly to gloveBoxContents without referencing the myStorage object.

You have some commented code (seen below).

myStorage.car.inside; // "glovebox"

If you were to assign the above myStorage reference to gloveBoxContents, then gloveBoxContents would have a reference to an object which looks like:

{  "glove box": "maps",   "passenger seat": "crumbs"  }

You want to access the “glove box” property of this object, so you need one for level added to your myStorage object reference.

HINT: Review the previous FCC challenge to access the value of the property you need.


#3

So something more like this?

var gloveBoxContents = myStorage[“glove box”]; // maps

it still didn’t run but it’s what I was going with on the previous challenge.


#4

myStorage does not have a direct property named ‘glove box’. However, ‘car’, which is a property of myStorage has an object with a property ‘inside’ which has an object with a property called ‘glove box’. This is why the chalenge is named Accessing Nested Objects. You can reference the nested properties using dot notation if there is no space in the property name or bracket notation if there is a space in the name.