question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.map()'s second argument contains the element too, instead of the index

See original GitHub issue

Given 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:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dtaocommented, Jan 25, 2017

And by tomorrow I meant “in roughly a year.”

Looking now.

1reaction
dtaocommented, Jan 25, 2017

I should have timed this better so that I fixed it on Feb 5, 2017.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found