Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md
2022-10-20 09:13:17 -07:00

2.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244cd الوصول إلى القائمات المتداخلة (Accessing Nested Arrays) 1 https://scrimba.com/c/cLeGDtZ 16160 accessing-nested-arrays

--description--

وكما رأينا في أمثلة سابقة، يمكن أن تحتوي الكائنات (objects) على كائنات متدخلة (nested objects) و قائمات متداخلة (nested arrays). على غرار الوصول إلى الكائنات متدخلة nested objects، يمكن ربط bracket notation في القائمة للوصول إلى القائمات متداخلة (nested arrays).

وفيما يلي مثال على كيفية الوصول إلى القائمة متداخلة nested) array):

const ourPets = [
  {
    animalType: "cat",
    names: [
      "Meowzer",
      "Fluffy",
      "Kit-Cat"
    ]
  },
  {
    animalType: "dog",
    names: [
      "Spot",
      "Bowser",
      "Frankie"
    ]
  }
];

ourPets[0].names[1];
ourPets[1].names[0];

ourPets[0].names[1] ستكوون المقطع نصي (string) الآتي Fluffy و ourPets[1].names[0] ستكون المقطع نصي (string) الآتي Spot.

--instructions--

باستخدام dot و bracket notation، وعيّن المتغير secondTree إلى العنصر الثاني في قائمة trees من object باسم myPlants.

--hints--

يجب أن تساوي secondTree مقطع (string) الآتي pine.

assert(secondTree === 'pine');

التعليمات البرميجة الخاص بك يجب أن يستخدم dot و bracket notation للوصول إلى myPlants.

assert(/=\s*myPlants\[1\].list\[1\]/.test(code));

--seed--

--after-user-code--

(function(x) {
  if(typeof x != 'undefined') {
    return "secondTree = " + x;
  }
  return "secondTree is undefined";
})(secondTree);

--seed-contents--

const myPlants = [
  {
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }
];

const secondTree = "";

--solutions--

const myPlants = [
  {
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }
];

const secondTree = myPlants[1].list[1];