Accessing Nested Objects Help! (Challenge 218)

Accessing Nested Objects Help! (Challenge 218)
0

#1

This JSON array stuff is really challenging me. I believe I’m messing up in accessing myStorage. Thanks for the help

Chase

What I’ve got so far

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

// Only change code below this line
gloveBoxContents.myStorage["car"];
var gloveBoxContents = "maps"; // 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/65.0.3325.181 Safari/537.36.

Link to the challenge:


#2

what are you trying to do with this?

step yourself through what you are trying to do and how you can achieve it. myStorage is an object which is just a key value data structure. You can access values of the data structure using either dot or bracket notation with the key. For example if I wanted to assign a variable to the value of the key ‘car’ I could do
var carValue = myStorage.car
or
var carValue = myStorage["car"]
now since this object has values that happen to be objects as well you can chain those commands to reach deeper levels. If i wanted to see what value was associated with the key ‘outside’ I could do
var outsideContent = myStorage.car['outside']
or
var outsideContent = myStorage.car.outside
or any other combination of bracket and dot calls.


#3

Thank you so much! This actually helped me complete it.