javascript icon indicating copy to clipboard operation
javascript copied to clipboard

[Arrays] To convert an array-like object to an array, use spreads ... instead of Array.from

Open maurozenoni opened this issue 8 years ago • 1 comments

I do not agree with what you can read in paragraph 4.4.

In fact, my understanding is that spread syntax can only be applied to iterable objects and not to array-like objects.

References:

Before changes introduced with issue #1084, you could read:

To convert an array-like object to an array, use Array.from

which I consider being correct.

Furthermore, I would personally expand it by saying:

To convert an iterable object or an array-like object to an array, use Array.from

That is because I agree with the authors of Javscript.info:

So, for the task of turning something into an array, Array.from tends to be more universal.

maurozenoni avatar Jul 02 '18 20:07 maurozenoni

Good point. This was added in #1549.

We should update this to indicate that iterables should use spreads, but array-like objects should use Array.from.

ljharb avatar Jul 03 '18 00:07 ljharb