Return value of forEach
Andrea Giammarchi
andrea.giammarchi at gmail.com
Fri Oct 16 12:32:34 UTC 2015
```js
const a = [1, 2, 3]
.map(square)
.map(x => console.log(x) || x )
.map(plus1)
.reduce(add);
```
Regards
On Fri, Oct 16, 2015 at 10:13 AM, Niloy Mondal <niloy.mondal84 at gmail.com>
wrote:
> Currently, `Array.prototype.forEach` returns `undefined`. It would be more
> useful if it returns the array itself.
>
> Say I have written some code like this...
>
> ```js
> const a = [1, 2, 3]
> .map(square)
> .map(plus1)
> .reduce(add);
> ```
>
> For some reason, I am not getting the expected output. For debugging, I
> would
> like the print the values after each step. My first initial reaction is to
> put a `forEach` step in between and print the values like so...
>
> ```js
> const a = [1, 2, 3]
> .map(square)
> .forEach(x => console.log(x))
> .map(plus1)
> .reduce(add);
> ```
>
> Unfortunately, this does not work as `forEach` returns `undefined`. I now
> have
> to comment out all the code below it. Having the _plug and play_ behaviour
> for
> `forEach` would be very convenient.
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151016/7ff7e2cf/attachment.html>
More information about the es-discuss
mailing list