2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: cf1111c1c11feddfaeb7bdef
|
2021-03-14 21:20:39 -06:00
|
|
|
title: 将一个数组嵌套在另一个数组中
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 1
|
2020-04-29 18:29:13 +08:00
|
|
|
videoUrl: 'https://scrimba.com/c/crZQZf8'
|
|
|
|
forumTopicId: 18247
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: nest-one-array-within-another-array
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-03-14 21:20:39 -06:00
|
|
|
您也可以在其他数组中嵌套数组,如:
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
2021-10-27 15:10:57 +00:00
|
|
|
const teams = [["Bulls", 23], ["White Sox", 45]];
|
2021-02-06 04:42:36 +00:00
|
|
|
```
|
|
|
|
|
2021-03-14 21:20:39 -06:00
|
|
|
这也叫做多维数组(<dfn>multi-dimensional array</dfn>)。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --instructions--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-03-14 21:20:39 -06:00
|
|
|
创建一个名为 `myArray` 的嵌套数组。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-03-14 21:20:39 -06:00
|
|
|
`myArray` 应该至少有一个数组嵌套在另一个数组中。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(Array.isArray(myArray) && myArray.some(Array.isArray));
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --after-user-code--
|
|
|
|
|
|
|
|
```js
|
|
|
|
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
|
|
|
```
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
// Only change code below this line
|
2021-10-27 15:10:57 +00:00
|
|
|
const myArray = [];
|
2021-01-13 03:31:00 +01:00
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```js
|
2021-10-27 15:10:57 +00:00
|
|
|
const myArray = [[1, 2, 3]];
|
2021-01-13 03:31:00 +01:00
|
|
|
```
|