Promise.reduce skips first array element.
See original GitHub issuehttp://jsfiddle.net/RichAyotte/t0rjhrab/
var pets = ['cat', 'dog', 'bird'];
Promise.reduce(pets, function(_, p) {
console.log(p);
});
Log
dog
bird
Issue Analytics
- State:
- Created 9 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
how to access zeroth element in reduce to count repeats in an ...
The reduce function works in a bit another way. It iterates over an array, aggregating items into a total value. The first argument...
Read more >Array.prototype.reduce() - JavaScript - MDN Web Docs
The reducer walks through the array element-by-element, at each step adding the current array value to the result from the previous step (this ......
Read more >One reduce() to rule them all — How to use reduce in JavaScript
Our first reducer — reducing an array to one value. Let's write a function which is going to sum together all numbers in...
Read more >Why Using reduce() to Sequentially Resolve Promises Works
When we use it to sequentially resolve promises, the reduce() loop isn't actually slowing down at all. It's completely synchronous, doing its ...
Read more >JavaScript Array reduce() Method - javatpoint
If we do not provide the initial value, the callback function will start its execution with index as 1, where it will skip...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
that is expected behavior. your 0th argument is being used as the initial value for the reduce
http://jsfiddle.net/cantremember/766up1an/
whereas pass a 3rd argument, such as
'mouse'
to Promise#reduce and you’ll see each element of your Array being visitedthanks, good to know. i must have overlooked that