Accessing Nested Objects 2

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
myStorage.car.inside["glove box"] = "maps" ;

var gloveBoxContents = myStorage; // Change this line

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/accessing-nested-objects

Do you have a question or problem?

Basically, there are 2 ways of handling object properties:

  • using dot notation, eg.: myStorage.outside.trunk (returns “jack”)
  • using bracket notation, eg.: myStorage[“car”][“outside”] (returns “jack”)

The advantage of bracket notation is that you can feed it variables, e.g.:

var someVariable = "car"
myStorage[someVariable]

More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

Hope this helps!