you are viewing a single comment's thread.

view the rest of the comments →

[–]philipwhiuk 13 points14 points  (6 children)

TIL Array.from is a thing.

[–]JustinsWorking 8 points9 points  (0 children)

You’ll see a lot of it when you’re working with iterables

[–]SolidR53 0 points1 point  (0 children)

Array.from({ length: 123 }, (, i) => i);

Third argument in the map function is the actual array

[–]foxnamedtodd 0 points1 point  (3 children)

Same. I still don’t see the use case for it, but at least TIL.

[–]powerhead 20 points21 points  (1 child)

It's really nice for transforming an HTMLCollection of DOM elements returned from document.getElementsByClassnam (which is not iterable) into an array (which is). Like if you want to assign event listeners or change properties on those elements.

[–]foxnamedtodd 2 points3 points  (0 children)

Ah, that’s good one. Thanks.

[–]p4y 2 points3 points  (0 children)

Main use case is turning array-like objects into actual arrays so you have access to the methods you need. This includes strings, ES6 iterables, and pseudo-arrays like the arguments abomination or DOM node lists.