Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maurozenoni opened this issue Jul 2, 2018 · 1 comment

Comments

@maurozenoni
Copy link
Contributor

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.

@ljharb
Copy link
Collaborator

ljharb commented Jul 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants