From 48ccd23c174e80ddc50e962ddbd4efe75751fc58 Mon Sep 17 00:00:00 2001 From: isLishude Date: Wed, 6 Dec 2017 09:32:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ES5=E4=B8=ADreduce=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=AF=B9=E6=95=B0=E7=BB=84=E7=A9=BA=E4=BD=8D=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```js [1,,2].reduce((x,y)=>{ console.log(x,y) return x+y }) // 输出 // 1 2 // 3 ``` --- docs/array.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/array.md b/docs/array.md index 3adaaed..dd2379e 100644 --- a/docs/array.md +++ b/docs/array.md @@ -728,7 +728,7 @@ Array(3) // [, , ,] ES5 对空位的处理,已经很不一致了,大多数情况下会忽略空位。 -- `forEach()`, `filter()`, `every()` 和`some()`都会跳过空位。 +- `forEach()`, `filter()`, `reduce()`, `every()` 和`some()`都会跳过空位。 - `map()`会跳过空位,但会保留这个值 - `join()`和`toString()`会将空位视为`undefined`,而`undefined`和`null`会被处理成空字符串。 @@ -742,6 +742,9 @@ ES5 对空位的处理,已经很不一致了,大多数情况下会忽略空 // every方法 [,'a'].every(x => x==='a') // true +// reduce方法 +[1,,2].reduce((x,y) => return x+y) // 3 + // some方法 [,'a'].some(x => x !== 'a') // false