Files
freeCodeCamp/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md

64 lines
1.3 KiB
Markdown
Raw Normal View History

---
id: bd7993c9c69feddfaeb8bdef
title: 使用 JavaScript 數組將多個值存儲在一個變量中
challengeType: 1
videoUrl: 'https://scrimba.com/c/crZQWAm'
forumTopicId: 18309
dashedName: store-multiple-values-in-one-variable-using-javascript-arrays
---
# --description--
使用數組(`array`),我們可以在一個地方存儲多個數據。
以左方括號開始定義一個數組,以右方括號結束,裏面每個元素之間用逗號隔開,例如:
```js
var sandwich = ["peanut butter", "jelly", "bread"]
```
# --instructions--
創建一個包含字符串(`string`)和數字( `number`)(按照字符串數字的順序)的數組 `myArray`
# --hints--
`myArray` 應該是一個數組(`array`)。
```js
assert(typeof myArray == 'object');
```
`myArray` 數組的第一個元素應該是一個字符串(`string`)。
```js
assert(typeof myArray[0] !== 'undefined' && typeof myArray[0] == 'string');
```
`myArray` 數組的第二個元素應該是一個數字(`number`)。
```js
assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number');
```
# --seed--
## --after-user-code--
```js
(function(z){return z;})(myArray);
```
## --seed-contents--
```js
// Only change code below this line
var myArray = [];
```
# --solutions--
```js
var myArray = ["The Answer", 42];
```