Assigning object properties to a variable (Accessing Nested Objects)

Assigning object properties to a variable (Accessing Nested Objects)


Hey guys, I am having trouble assigning object properties to a variable. The challenge that I am specifically working on is: Basic Java - Accessing Nested Objects.

I have been trying to assign the property (“glove box”) of the object (myStorage) to the new variable (gloveBoxContents) but, either I am getting [object.Object] or Undefined.

I know that code is read/assigned/declared from right to left, but I am struggling with this one and how to structure it. Any help would be greatly appreciated.




Do you understand how the example works?

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"


I am not sure. This is what I think I know.

ourStorage (Object), “.” or dot notation < calls on the property cabinet and property [“top drawer”]. Top drawer is in bracket notation because there is a space between the words “Top_drawer”. folder 2 holds the value “secrets”.


Okay, and how are you trying to assign the property currently?


If I was to right it similar to the example I would do something like this. Keeping in mind storing the value of the property into the new variable.

var gloveBoxContent =[“glove box”]; (compiles as: can’t find variable gloveBoxContent

var gloveBoxContent = [“glove box”];
Thanks for the response!


Can you post your entire code into the post, just so we know exactly what you are trying. It may be a typo somewhere.

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

// Only change code below this lin
var gloveBoxContent =["glove box"]; // Change this line


Thanks for the response Dawson


It could be the " // Only change code below this lin " missing the “e” . The way you have accessed it looks correct. Would you try correcting that and see if you get the solution?


Just checked, and nope, that wasn’t it :confused:


I see one more typo! Carefully look at the instructions and look at your error message closely. See if you can find it! Then you should be good to go :slight_smile:


Like @addisonday says, you have a typo. Look at the variable name you wrote compared to what the instructions ask to you use for the variable name. It is one letter off.


LOL! Addisonday-thankyou. Wow…


Dawson thank you for the help too. This community is great. Truly much appreciated. Wow, that was so little but critical.


@JakeVittoriso - Glad we could be of assistance. Typos are one of the biggest sources of errors when programming.

FYI - You might have noticed that I edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard.


thanks JakeVittoriso


How would I bracket several words? For example, suppose instead of this:

var gloveBoxContents =[“glove box”];

If “inside” was “inside car”
Can you do this:

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

I am just wondering - it seems like the bracket was useful here because glove box is 2 words, and so using the dot notation would not work. But, suppose if you have 2 phrases next to each other, how do you properly notate?

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

var gloveBoxContents =[“glove box”]; // Change this line


Not exactly sure what you mean by 2 phrases next to each other. Can you show an example object and tell us what property value you are trying to reference?