Accessing Nested Objects
The sub-properties of objects can be accessed by chaining together the dot or bracket notation.
Here is a nested object:
const ourStorage = {
"desk": {
"drawer": "stapler"
},
"cabinet": {
"top drawer": {
"folder1": "a file",
"folder2": "secrets"
},
"bottom drawer": "soda"
}
};
ourStorage.cabinet["top drawer"].folder2;
ourStorage.desk.drawer;
ourStorage.cabinet["top drawer"].folder2
would be the string secrets
, and ourStorage.desk.drawer
would be the string stapler
.
Access the myStorage
object and assign the contents of the glove box
property to the gloveBoxContents
variable. Use dot notation for all properties where possible, otherwise use bracket notation.
Tests
- Waiting: 1.
gloveBoxContents
should equal the stringmaps
. - Waiting: 2. Your code should use dot notation, where possible, to access
myStorage
. - Waiting: 3.
gloveBoxContents
should still be declared withconst
. - Waiting: 4. You should not change the
myStorage
object.
/** * Your test output will go here */