Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md

2.2 KiB
Raw Blame History

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