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
72 lines
1.8 KiB
Markdown
72 lines
1.8 KiB
Markdown
---
|
|
id: 56592a60ddddeae28f7aa8e1
|
|
title: Access Multi-Dimensional Arrays With Indexes
|
|
challengeType: 1
|
|
forumTopicId: 16159
|
|
dashedName: access-multi-dimensional-arrays-with-indexes
|
|
---
|
|
|
|
# --description--
|
|
|
|
One way to think of a <dfn>multi-dimensional</dfn> array, is as an *array of arrays*. 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.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
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` .
|
|
|
|
**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0][0]` and even this `array [0] [0]` is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
|
|
|
|
# --instructions--
|
|
|
|
Using bracket notation select an element from `myArray` such that `myData` is equal to `8`.
|
|
|
|
# --hints--
|
|
|
|
`myData` should be equal to `8`.
|
|
|
|
```js
|
|
assert(myData === 8);
|
|
```
|
|
|
|
You should be using bracket notation to read the correct value from `myArray`.
|
|
|
|
```js
|
|
assert(/myData=myArray\[2\]\[1\]/.test(__helpers.removeWhiteSpace(__helpers.removeJSComments(code))));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
const myArray = [
|
|
[1, 2, 3],
|
|
[4, 5, 6],
|
|
[7, 8, 9],
|
|
[[10, 11, 12], 13, 14],
|
|
];
|
|
|
|
const myData = myArray[0][0];
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]];
|
|
const myData = myArray[2][1];
|
|
```
|