Accessing Nested

Accessing Nested
0.0 0

#1

Tell us what’s happening:

Your code so far

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

// Only change code below this line

var gloveBoxContents =myStorage.["car"."inside"].glove box;

Your browser information:

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

Link to the challenge:


help me plz


#2

You are trying to use a mix of bracket and dot notation, but not correctly.

Let’s say we had the following object:

var myHouse = {
  "kitchen": {
    "refrigerator": {
      "top shelf": "milk",
      "door": "salad dressing"
     },
    "oven": {
      "top rack": "casserole",
      "bottom rack": "chicken"
    }
  }
};

If I wanted to access “salad dressing” and wanted to just use bracket notation, I would write:

var food = myHouse["kitchen"]["refrigerator"]["door"];

If I wanted to use just dot notation, I would write:

var food = myHouse.kitchen.refrigerator.door;

If wanted to use a mix of bracket and dot notation I would write:

var food = myHouse["kitchen"].refrigerator["door"];
// OR
var food = myHouse["kitchen"]["refrigerator"].door;
// OR
var food = myHouse.kitchen["refrigerator"].door;

If the property you are trying to reference has a name with spaces in it, then you MUST use bracket notation for that particular property. For example, if I wanted to use a mix of dot and bracket notation to access “chicken” in myHouse, then I would have to write:

var food = myHouse.kitchen.oven["bottom rack"];

Now see if you can use the correct syntax to get the contents of “glove box”