mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-31 06:01:50 -05:00
2.4 KiB
2.4 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244cc | الوصول إلى الكائنات المتداخلة (Accessing Nested Objects) | 1 | https://scrimba.com/c/cRnRnfa | 16161 | accessing-nested-objects |
--description--
يمكن الوصول للخصائص الفرعية (sub-properties) للكائنات (objects) من طريق ربطه برمز النقطة أو القوس.
فيما يلي كائن متداخل (nested object):
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 مقطع (string) الآتي secrets, وسيكون ourStorage.desk.drawer مقطع (string) الآتي stapler.
--instructions--
الوصول إلى الكائن myStorage وعيّن محتوى الخاصية glove box إلى المتغير gloveBoxContents. حاول استخدام النُّقَط (dot notation) للوصول للخصائص (properties) بقدر الإمكان، وإلا فيمكنك استخدام الأقواس[] (bracket notation).
--hints--
يجب أن يساوي gloveBoxContents مقطع (string) الآتي maps.
assert(gloveBoxContents === 'maps');
التعليمات البرمجية الخاص بك يجب أن يستخدم dot notation و bracket notation للوصول إلى myStorage.
assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
gloveBoxContents should still be declared with const.
assert.match(code, /const\s+gloveBoxContents\s*=/)
--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"];