Accessing Nested Objects

Accessing Nested Objects
0.0 0



So for the Javascript challenges, I am stuck in the “Accessing Nested Objects” part.

The sub-properties of objects can be accessed by chaining together the dot or bracket notation.

Here is a nested object:

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    "bottom drawer": "soda"
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"

Access the myStorage object and assign the contents of the glove box property to the gloveBoxContents variable. Use bracket notation for properties with a space in their name.

I don’t know if it’s because I don’t understand english ? I tried doing this

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

// Only change code below this line["glove box"];

var gloveBoxContents = ""; // Change this line

But I am still stuck. Can somebody help me please ? Plus, when I click on the get hints I can’t find anything… :frowning:


You are close. The instructions say to assign the contents of the glove box property to the gloveBoxContents variable. You currently have assigned a blank string to gloveBoxContents. You just need to move one line to a part of another.


I actually feel stupid right now. -_- I kept doing that but got stuck with an error saying dot notation something like that. But now it’s all okay ! Thank you! :smiley:


how you slove this, can you send me the code


Instead of asking for the solution, why not post the code you have so far for the challenge and ask questions for parts you are having trouble understanding.


Solution: var gloveBoxContents =["glove box"];


Thanks I couldnt figure it out I have them on separate lines.


var gloveBoxContents =[“glove box”];


This code doesn’t work because there is a space in glove box correct that is why you use the brackets?
var myStorage = {
“car”: {
“inside”: {
“glove box”: “maps”,
“passenger seat”: “crumbs”
“outside”: {
“trunk”: “jack”

// Only change code below this line

var gloveBoxContents =[“inside”].glove box;


You are correct. Object properties with spaces in their names require the use of brackets.


ahhh, thanks so much. I was looking for an explanation and couldn’t find one until now. Thank you!