Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md
2022-10-26 12:51:22 -07:00

2.4 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56592a60ddddeae28f7aa8e1 Доступ до багатовимірних масивів за допомогою індексів 1 https://scrimba.com/c/ckND4Cq 16159 access-multi-dimensional-arrays-with-indexes

--description--

Багатовимірні масиви можна також описати як масиви в масивах. When you use brackets to access your array, the first set of brackets refers to the entries in the outermost (the first level) array, and each additional pair of brackets refers to the next level of entries inside.

Наприклад

const arr = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
  [[10, 11, 12], 13, 14]
];

const subarray = arr[3];
const nestedSubarray = arr[3][0];
const element = arr[3][0][1];

In this example, subarray has the value [[10, 11, 12], 13, 14], nestedSubarray has the value [10, 11, 12], and element has the value 11 .

Примітка: ніколи не вставляйте пробіл між ім'ям масиву і квадратними дужками, наприклад, так array [0][0] і навіть так array [0] [0] не можна робити. Незважаючи на те, що для JavaScript це є дрібницею, ця звичка може ускладнити читання коду іншими програмістами.

--instructions--

За допомогою квадратних дужок виберіть елемент із myArray таким чином, щоб myData дорівнював 8.

--hints--

myData має дорівнювати 8.

assert(myData === 8);

Ви маєте використовувати квадратні дужки, щоб зчитати правильне значення з myArray.

assert(/myData=myArray\[2\]\[1\]/.test(__helpers.removeWhiteSpace(code)));

--seed--

--after-user-code--

if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " myArray: " + JSON.stringify(myArray);})();}

--seed-contents--

const myArray = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
  [[10, 11, 12], 13, 14],
];

const myData = myArray[0][0];

--solutions--

const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]];
const myData = myArray[2][1];