|
@@ -1,7 +1,7 @@
|
|
|
<!--
|
|
|
* @Author: your name
|
|
|
* @Date: 2021-08-20 16:17:21
|
|
|
- * @LastEditTime: 2021-08-24 17:31:58
|
|
|
+ * @LastEditTime: 2021-08-24 17:58:21
|
|
|
* @LastEditors: Please set LastEditors
|
|
|
* @Description:
|
|
|
* @FilePath: \md-\js\合并数组中的key值.md
|
|
@@ -115,12 +115,34 @@ const res = [...map.values()]
|
|
|
- `array`原始数组,当前循环的原始数组
|
|
|
> [!tip]
|
|
|
> 一个偏向于官方风格的示例,用来求数组中的和
|
|
|
-
|
|
|
+
|
|
|
+执行下方代码
|
|
|
```js
|
|
|
-[0,1,2,3].reduce((accumulator,currentValue,index,array)=>{
|
|
|
- console.log(`accumulator:${accumulator}\ncurrentValue:${currentValue}\nindex:${index}`)
|
|
|
+let result = [0,1,2,3].reduce((accumulator,currentValue,index,array)=>{
|
|
|
+ console.log(`accumulator:${accumulator}\ncurrentValue:${currentValue}\nindex:${index}\n`)
|
|
|
return accumulator + currentValue
|
|
|
},-1)
|
|
|
+console.log(`最后返回的值${result}`)
|
|
|
+```
|
|
|
+控制台输出
|
|
|
+```
|
|
|
+accumulator:-1
|
|
|
+currentValue:0
|
|
|
+index:0
|
|
|
+
|
|
|
+accumulator:-1
|
|
|
+currentValue:1
|
|
|
+index:1
|
|
|
+
|
|
|
+accumulator:0
|
|
|
+currentValue:2
|
|
|
+index:2
|
|
|
+
|
|
|
+accumulator:2
|
|
|
+currentValue:3
|
|
|
+index:3
|
|
|
+
|
|
|
+最后返回的值5
|
|
|
```
|
|
|
|
|
|
### 2. `js`解构赋值
|