## JSArray 对象

JavaScript 中的 Array 对象是用于存储多个值的特殊类型的对象。

Array 是按顺序存储元素的，可以根据索引（从 0 开始）来访问它们。

### 创建数组

可以通过几种方式创建数组：

使用 Array 构造函数：

```
let arr1 = new Array(3);  // 创建一个长度为 3 的空数组
let arr2 = new Array(1, 2, 3);  // 创建一个包含 1, 2, 3 的数组
```

使用字面量（推荐）：

```
let arr = [1, 2, 3];  // 创建一个包含 1, 2, 3 的数组
```

第一个数组元素的索引值为 0，第二个索引值为 1，以此类推

### 数组属性



### 对象方法



#### forEach()

forEach() 方法用于调用数组的每个元素，并将元素传递给回调函数。

**注意:** forEach() 对于空数组是不会执行回调函数的。

```
array.forEach(callbackFn(currentValue, index, arr), thisValue)
```

其他形式的语法格式：

```js
// 箭头函数
forEach((element) => { /* … */ })
forEach((element, index) => { /* … */ })
forEach((element, index, array) => { /* … */ })

// 回调函数
forEach(callbackFn)
forEach(callbackFn, thisArg)

// 内联回调函数
forEach(function(element) { /* … */ })
forEach(function(element, index) { /* … */ })
forEach(function(element, index, array){ /* … */ })
forEach(function(element, index, array) { /* … */ }, thisArg)
```

| 参数                                   | 描述                                                         |
| :------------------------------------- | :----------------------------------------------------------- |
| *callbackFn(currentValue, index, arr)* | 必需。 数组中每个元素需要调用的函数。 函数参数:参数描述*currentValue*必需。当前元素*index*可选。当前元素的索引值。*arr*可选。当前元素所属的数组对象。 |
| *thisValue*                            | 可选。传递给函数的值一般用 "this" 值。 如果这个参数为空， "undefined" 会传递给 "this" 值 |