add:数组的其他方法

This commit is contained in:
qianguyihao
2019-02-03 19:50:42 +08:00
parent 89f865611a
commit be3cd9b7cf
8 changed files with 261 additions and 271 deletions

View File

@@ -85,8 +85,9 @@ ES6中的字符串扩展用得少而且逻辑相对简单。如下
## 数组的扩展
### 扩展1
> 下面提到的数组的几个方法更详细的内容可以看《03-JavaScript基础/17-数组的其他方法.md》。
### 扩展1Array.from()
```javascript
Array.from(伪数组/可遍历的对象)
@@ -131,8 +132,7 @@ ES6中的字符串扩展用得少而且逻辑相对简单。如下
![](http://img.smyhvae.com/20180402_1125.png)
### 扩展2
### 扩展2Array.of()
```javascript
Array.of(value1, value2, value3)
@@ -149,7 +149,7 @@ ES6中的字符串扩展用得少而且逻辑相对简单。如下
console.log(arr);
```
### 扩展3
### 扩展3find() 和 findIndex()
**方法1**
@@ -158,19 +158,7 @@ ES6中的字符串扩展用得少而且逻辑相对简单。如下
find(function(item, index, arr){return true})
```
**作用**找出第一个满足「指定条件返回true」的元素。
举例:
```javascript
let arr = [2, 3, 2, 5, 7, 6];
let result = arr.find(function (item, index) {
return item > 4; //遍历数组arr一旦发现有第一个元素大于4就把这个元素返回
});
console.log(result); //打印结果5
```
**作用**:找出**第一个**满足「指定条件返回true」的元素。
**方法2**
@@ -180,19 +168,6 @@ ES6中的字符串扩展用得少而且逻辑相对简单。如下
**作用**找出第一个满足「指定条件返回true」的元素的index。
举例:
> 我们直接把上面的代码中的find方法改成findIndex即可。
```javascript
let arr = [2, 3, 2, 5, 7, 6];
let result = arr.findIndex(function (item, index) {
return item > 4; //遍历数组arr一旦发现有第一个元素大于4就把这个元素的index返回
});
console.log(result); //打印结果3
```
## 对象的扩展