Accessing Nested Objects in OBJECT section of Java script

Tell us what’s happening:

i’m just stucked in this lesson any one here to help me .

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 = "glove box"; // Change this line
myStorage.car['inside'].gloveBoxContents;


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

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

You are quite close to getting the right answer.

First of all, you should only be changing one line:

var gloveBoxContents = //your code goes here

The point of the exercise is really to work out when you should use dot notation and when you should use bracket notation. Essential, you will want to use dot notation whenever possible. The times bracket notation comes in handy, and must be used, are when you have a key with spaces, i.e "passenger seat" or when you want to use a variable to access the object.

you final code will look something like this:

var gloveBoxContents = myStorage.car.somethingWithNoSpaces["something with spaces"];

Hope this helps :slight_smile:

1 Like

After spending some i got this `// 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”]; // Change this line`

If it is still not working, then I think the problem is you have the wrong quotes around glove box. At least when I tried your code that was the only thing that stopped it from working. You can also use single quotes' '.

On the forum, You need to use back ticks to get you code to format well. Use Single back ticks for small bits of code: `Code`. And for larger:
```
Code
```