2019-02-19 11:34:27 +03:00

1.9 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244cc Accessing Nested Objects 1 访问嵌套对象

Description

可以通过将点或括号表示法链接在一起来访问对象的子属性。这是一个嵌套对象:
var ourStorage = {
“桌子”:{
“抽屉”:“订书机”
}
“内阁”:{
“顶级抽屉”:{
“folder1”“一个文件”
“folder2”“秘密”
}
“底部抽屉”:“苏打水”
}
};
ourStorage.cabinet [“top drawer”]。folder2; //“秘密”
ourStorage.desk.drawer; //“订书机”

Instructions

访问myStorage对象并将glove box属性的内容分配给gloveBoxContents变量。对于名称中包含空格的属性,请使用括号表示法。

Tests

tests:
  - text: <code>gloveBoxContents</code>应该等于“地图”
    testString: 'assert(gloveBoxContents === "maps", "<code>gloveBoxContents</code> should equal "maps"");'
  - text: 使用点和括号表示法访问<code>myStorage</code>
    testString: 'assert(/=\s*myStorage\.car\.inside\[\s*("|")glove box\1\s*\]/g.test(code), "Use dot and bracket notation to access <code>myStorage</code>");'

Challenge Seed

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

var gloveBoxContents = undefined; // Change this line

After Test

console.info('after the test');

Solution

// solution required