--- id: bd7993c9c69feddfaeb8bdef challengeType: 1 videoUrl: 'https://scrimba.com/c/crZQWAm' forumTopicId: 18309 title: 使用 JavaScript 数组将多个值存储在一个变量中 --- ## Description
使用数组,我们可以在一个地方存储多个数据。 以左方括号[开始定义一个数组,以右方括号]结束,里面每个元素之间用逗号隔开,例如: var sandwich = ["peanut butter", "jelly", "bread"].
## Instructions
创建一个包含字符串数字的数组myArray提示
如果你遇到困难,请参考文本编辑器中的示例代码。
## Tests
```yml tests: - text: myArray应该是一个数组。 testString: assert(typeof myArray == 'object'); - text: myArray数组的第一个元素应该是一个字符串。 testString: assert(typeof myArray[0] !== 'undefined' && typeof myArray[0] == 'string'); - text: myArray数组的第二个元素应该是一个数字。 testString: assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number'); ```
## Challenge Seed
```js // Example var ourArray = ["John", 23]; // Only change code below this line. var myArray = []; ```
### After Test
```js (function(z){return z;})(myArray); ```
## Solution
```js var myArray = ["The Answer", 42]; ```