--- id: 56533eb9ac21ba0edf2244cc title: Accessing Nested Objects challengeType: 1 videoUrl: '' localeTitle: 访问嵌套对象 --- ## Description
可以通过将点或括号表示法链接在一起来访问对象的子属性。这是一个嵌套对象:
var ourStorage = {
“桌子”:{
“抽屉”:“订书机”
},
“内阁”:{
“顶级抽屉”:{
“folder1”:“一个文件”,
“folder2”:“秘密”
},
“底部抽屉”:“苏打水”
}
};
ourStorage.cabinet [“top drawer”]。folder2; //“秘密”
ourStorage.desk.drawer; //“订书机”
## Instructions
访问myStorage对象并将glove box属性的内容分配给gloveBoxContents变量。对于名称中包含空格的属性,请使用括号表示法。
## Tests
```yml tests: - text: gloveBoxContents应该等于“地图” testString: 'assert(gloveBoxContents === "maps", "gloveBoxContents should equal "maps"");' - text: 使用点和括号表示法访问myStorage testString: 'assert(/=\s*myStorage\.car\.inside\[\s*("|")glove box\1\s*\]/g.test(code), "Use dot and bracket notation to access myStorage");' ```
## Challenge Seed
```js // Setup var myStorage = { "car": { "inside": { "glove box": "maps", "passenger seat": "crumbs" }, "outside": { "trunk": "jack" } } }; var gloveBoxContents = undefined; // Change this line ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```