Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md
2023-09-06 12:29:19 -07:00

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');

Your code should use dot notation, where possible, to access myStorage.

assert.match(code, /myStorage\.car\.inside/);

gloveBoxContents should still be declared with const.

assert.match(code, /const\s+gloveBoxContents\s*=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]|const\s*{\s*('|")glove box\2:\s*gloveBoxContents\s*}\s*=\s*myStorage\.car\.inside;/);

--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"];