2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244cc | ネストされたオブジェクトへのアクセス | 1 | https://scrimba.com/c/cRnRnfa | 16161 | accessing-nested-objects |
--description--
オブジェクトの下位プロパティには、ドット記法またはブラケット記法によるチェーンでアクセスできます。
次はネストされたオブジェクトです。
const ourStorage = {
"desk": {
"drawer": "stapler"
},
"cabinet": {
"top drawer": {
"folder1": "a file",
"folder2": "secrets"
},
"bottom drawer": "soda"
}
};
ourStorage.cabinet["top drawer"].folder2;
ourStorage.desk.drawer;
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));
--seed--
--after-user-code--
(function(x) {
if(typeof x != 'undefined') {
return "gloveBoxContents = " + x;
}
return "gloveBoxContents is undefined";
})(gloveBoxContents);
--seed-contents--
const myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
const gloveBoxContents = undefined;
--solutions--
const myStorage = {
"car":{
"inside":{
"glove box":"maps",
"passenger seat":"crumbs"
},
"outside":{
"trunk":"jack"
}
}
};
const gloveBoxContents = myStorage.car.inside["glove box"];