.map()'s second argument contains the element too, instead of the index
See original GitHub issueGiven this I expecting the consecutive array index in i
.
Lazy({key1: "value1", key2: "value2"})
.keys()
.map((key, i) => {
console.log(key, i);
})
.value();
I am expecting this output:
key1 0
key2 1
But I am getting also the element in i
:
key1 key1
key2 key2
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
map second argument is current value instead of index
The first value of the map callback is the looped item value. Because you are using Array.from with no init callback, i will...
Read more >Array.prototype.map() - JavaScript - MDN Web Docs
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array....
Read more >Deep Dive into JavaScript's Array Map Method - Robin Wieruch
The second argument to the callback function is the index of the item that we are currently processing. Taking our example array of...
Read more >How to Use Map, Filter, and Reduce in JavaScript - Code
With map , you can operate on the element directly, rather than having to index into the array. You don't have to create...
Read more >Understanding Map and Set in JavaScript | Tania Rascia
Maps have elements of both Objects (a unique key/value pair ... The first argument will be the key, and the second argument will...
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 FreeTop 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
Top GitHub Comments
And by tomorrow I meant “in roughly a year.”
Looking now.
I should have timed this better so that I fixed it on Feb 5, 2017.