Accessing Nested Objects in json

Accessing Nested Objects in json
0.0 0

#1

Tell us what’s happening:

i’ve got stuck please help

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 ="maps"; // Change this line
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.140 Safari/537.36.


#3

what do you mean by that :thinking:


#4

You can access properties of an object using dot notation or bracket notation. So to access the outside property on myStorage you can use: myStorage.outside or myStorage["outside"].

The same works for a property of an object inside an object like myStorage (object) > outside (object) > trunk (property). You can then use: myStorage.outside.trunk or myStorage.outside["trunk"] or myStorage["outside"].trunk or myStorage["outside"][“trunk”].