Files
freeCodeCamp/guide/chinese/javascript/standard-objects/array/array-length/index.md
2018-10-16 21:32:40 +05:30

26 lines
619 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Array Length
localeTitle: 数组长度
---
## 数组长度
`length`是JavaScript中数组的一个属性它返回或设置给定数组中的元素数。
可以像这样返回数组的`length`属性。
```js
let desserts = ["Cake", "Pie", "Brownies"];
console.log(desserts.length); // 3
```
赋值运算符与`length`属性一起可用于设置数组中的元素数量,如此。
```js
let cars = ["Saab", "BMW", "Volvo"];
cars.length = 2;
console.log(cars.length); // 2
```
#### 更多信息:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/length