Files
freeCodeCamp/guide/chinese/javascript/standard-objects/array/array-length/index.md

26 lines
619 B
Markdown
Raw Normal View History

---
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