2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Accessing Nested Objects
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Accessing Nested Objects
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
|
|
|
Use bracket notation for properties with a space in their name.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
If we look at our object:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
var myStorage = {
|
2019-07-24 00:59:27 -07:00
|
|
|
car: {
|
|
|
|
inside: {
|
2018-10-12 15:37:13 -04:00
|
|
|
"glove box": "maps",
|
|
|
|
"passenger seat": "crumbs"
|
2019-07-24 00:59:27 -07:00
|
|
|
},
|
|
|
|
outside: {
|
|
|
|
trunk: "jack"
|
2018-10-12 15:37:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
Our object name is `myStorage`.
|
|
|
|
|
|
|
|
|-- Inside that we have a nested object called `car`.
|
|
|
|
|
|
|
|
|--- Inside that we have two more called `inside` and `outside` each with their
|
|
|
|
own properties
|
|
|
|
|
|
|
|
You can visualize the object structure like this, if it helps:
|
|
|
|
|
|
|
|
```
|
|
|
|
myStorage
|
|
|
|
|-- car
|
|
|
|
|--- inside
|
|
|
|
|----- glove box: maps
|
|
|
|
|----- passenger seat: crumbs
|
|
|
|
|--- outside
|
|
|
|
|----- trunk: jack
|
|
|
|
```
|
|
|
|
|
|
|
|
We are asked to assign the contents of `glove box` ,
|
|
|
|
which we can see is nested in the `inside` object,
|
|
|
|
which in turn, is nested in the `car` object.
|
|
|
|
|
|
|
|
We can use dot notation to access the `glove box` as follows:
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
|
|
|
var gloveBoxContents = myStorage.car.inside[complete here]
|
2018-10-12 15:37:13 -04:00
|
|
|
```
|
|
|
|
You must replace `complete here` with the correct way to access the property.
|
|
|
|
See clue above if you get stuck.
|