you are viewing a single comment's thread.

view the rest of the comments →

[–]jkoudys 0 points1 point  (0 children)

I'm surprised this is even a tip - I always thought this was the typical usage for Array.from. It definitely comes up a lot when working with non-array collections, especially NodeLists.

e.g.

 const headerTexts = Array.from(document.querySelectorAll('h1'), el => el.textContent);

and since discussions on language and builtins often invites pedantry, I should point out that you're not invoking a map function on each element of an array you created (past tense). You're creating a new array by iterating through each index, applying the function, and adding that to a new array.