dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 56bbb991ad1ed5201cd392ca | Access Array Data with Indexes | 1 | 16158 | access-array-data-with-indexes |
--description--
We can access the data inside arrays using indexes.
Array indexes are written in the same bracket notation that strings use, except that instead of specifying a character, they are specifying an entry in the array. Like strings, arrays use zero-based indexing, so the first element in an array has an index of 0.
Example
const array = [50, 60, 70];
console.log(array[0]);
const data = array[1];
The console.log(array[0]) prints 50, and data has the value 60.
--instructions--
Create a variable called myData and set it to equal the first value of myArray using bracket notation.
--hints--
The variable myData should equal the first value of myArray.
assert(
(function () {
if (
typeof myArray !== 'undefined' &&
typeof myData !== 'undefined' &&
myArray[0] === myData
) {
return true;
} else {
return false;
}
})()
);
The data in variable myArray should be accessed using bracket notation.
assert(
(function () {
if (__helpers.removeJSComments(code).match(/\s*=\s*myArray\[0\]/g)) {
return true;
} else {
return false;
}
})()
);
--seed--
--seed-contents--
const myArray = [50, 60, 70];
--solutions--
const myArray = [50, 60, 70];
const myData = myArray[0];