Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md
2022-12-15 14:51:02 +00:00

88 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: 56bbb991ad1ed5201cd392ca
title: Доступ до даних масиву за допомогою індексів
challengeType: 1
videoUrl: 'https://scrimba.com/c/cBZQbTz'
forumTopicId: 16158
dashedName: access-array-data-with-indexes
---
# --description--
Ми можемо отримати доступ до даних всередині масивів за допомогою <dfn>індексів</dfn>.
Індекс масивів, так як і в рядках, написаний у дужковій нотації. Однак вони вказують не символ, а певний запис у масиві. Як і рядки, масиви використовують індексування <dfn>на основі нуля</dfn>, тому перший елемент у масиві має індекс `0`.
<br>
**Наприклад**
```js
const array = [50, 60, 70];
console.log(array[0]);
const data = array[1];
```
`console.log(array[0])` друкує `50`, і `data` має значення `60`.
# --instructions--
Створіть змінну під назвою `myData` і встановіть її рівною першому значенню `myArray`, використовуючи дужкову нотацію.
# --hints--
Змінна `myData` повинна дорівнювати першому значенню `myArray`.
```js
assert(
(function () {
if (
typeof myArray !== 'undefined' &&
typeof myData !== 'undefined' &&
myArray[0] === myData
) {
return true;
} else {
return false;
}
})()
);
```
До даних у змінній `myArray` можна отримати доступ за допомогою дужкової нотації.
```js
assert(
(function () {
if (code.match(/\s*=\s*myArray\[0\]/g)) {
return true;
} else {
return false;
}
})()
);
```
# --seed--
## --after-user-code--
```js
if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,z){return 'myArray = ' + JSON.stringify(y) + ', myData = ' + JSON.stringify(z);})(myArray, myData);}
```
## --seed-contents--
```js
const myArray = [50, 60, 70];
```
# --solutions--
```js
const myArray = [50, 60, 70];
const myData = myArray[0];
```