Categories
JavaScript Answers

How to call map() on an iterator with JavaScript?

Spread the love

To call map() on an iterator with JavaScript, we convert the iterator into an array.

For instance, we write

Array.from(m).map(([key, value]) => {
  //...
});

to call Array.from with iterator m to convert it to an array.

Then we get the key and value from the array parameter in the map callback and do what we want with the values.

Conclusion

To call map() on an iterator with JavaScript, we convert the iterator into an array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *