Accessing Nested Object

Accessing Nested Object
0

#1

Tell us what’s happening:
What is wrong with my code? I get an error stating “Use dot and bracket notation to access myStorage”.

Your code so far

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

// Only change code below this line

var gloveBoxContents = myStorage.car["inside"].glovebox; // Change this line
var gloveBoxContents = myStorage.car.inside.glovebox;

Your browser information:

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

Link to the challenge:


#2

You were not supposed to change the glove box in the setup.

Now to access a value from a property with spaces (or some other punctuation), you’ll have to use bracket notation. Like inside['glove box'].


#3

var gloveBoxContents = myStorage.car.inside[“glove box”];
LOl, thanks