Accessing Nested Objects - clarification

Accessing Nested Objects - clarification
0.0 0

#1

Tell us what’s happening:

If the key “glove box” was “gloveBox” then I could have done myStorage.car.inside.gloveBox or myStorage[“car”][“inside”][“gloveBox”] and got the right answer right?

Your code so far


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

var gloveBoxContents = myStorage.car.inside["glove box"]; // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects


#2

Correct. You can only use dotted notation when the prop key is known, and is a string


#3

Just to clarify, it’s slightly more restrictive than that: It needs to be a valid “JavaScript identifier”, meaning that it can be made up of alphanumerical characters, underscores, and dollar signs but can’t start with a number. That is different than the JS concept of a “string”.