2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244cc
title: Accessing Nested Objects
challengeType: 1
2019-08-28 16:26:13 +03:00
videoUrl: https://scrimba.com/c/cRnRnfa
forumTopicId: 16161
2018-10-10 18:03:03 -04:00
localeTitle: Доступ к вложенным объектам
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
Доступ к дополнительным свойствам объектов можно получить, объединив нотацию точки или скобки. Вот вложенный объект: < blockquote > var ourStorage = { < br > " стол письменный" : { < br > «ящик»: «степлер» < br > }, < br > «кабинет»: { < br > " верхний ящик" : { < br > «folder1»: «файл», < br > " folder2" : " секреты" < br > }, < br > «нижний ящик»: «сода» < br > } < br > }; < br > ourStorage.cabinet [" верхний ящик" ]. folder2; // " секреты" < br > ourStorage.desk.drawer; // " степлер" < / blockquote >
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
Войдите в объект < code > myStorage< / code > и назначьте содержимое свойства < code > glove box< / code > переменной < code > gloveBoxContents< / code > . Используйте обозначения в виде скобок для свойств с пробелом в их имени.
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > gloveBoxContents</ code > should equal "maps"
testString: assert(gloveBoxContents === "maps");
- text: Use dot and bracket notation to access < code > myStorage</ code >
testString: assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
var gloveBoxContents = undefined; // Change this line
```
< / div >
2019-08-28 16:26:13 +03:00
### After Tests
2018-10-10 18:03:03 -04:00
< div id = 'js-teardown' >
```js
2019-08-28 16:26:13 +03:00
(function(x) {
if(typeof x != 'undefined') {
return "gloveBoxContents = " + x;
}
return "gloveBoxContents is undefined";
})(gloveBoxContents);
2018-10-10 18:03:03 -04:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
var myStorage = {
"car":{
"inside":{
"glove box":"maps",
"passenger seat":"crumbs"
},
"outside":{
"trunk":"jack"
}
}
};
var gloveBoxContents = myStorage.car.inside["glove box"];
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >