1.0 KiB

id, title, challengeType, videoUrl, forumTopicId
id title challengeType videoUrl forumTopicId
56533eb9ac21ba0edf2244cc 访问嵌套对象 1 https://scrimba.com/c/cRnRnfa 16161

--description--

通过串联起来的点操作符或中括号操作符来访问对象的嵌套属性。

下面是一个嵌套的对象:

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"

--instructions--

读取myStorage对象,将glove box属性的内容赋值给变量gloveBoxContents。在适用的地方使用点操作符来访问属性,否则使用中括号操作符。

--hints--

gloveBoxContents应该等于"maps"。

assert(gloveBoxContents === 'maps');

应使用点操作符和中括号操作符来访问myStorage

assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));

--solutions--