Skip to content

Prefer the spread operator over Array.from() #120

@sindresorhus

Description

@sindresorhus

Fail

const set = new Set([1, 2]);
Array.from(set).map(() => {});

Pass

const set = new Set([1, 2]);
[...set].map(() => {});

The only difference between them is that Array.from() also works on array-like objects, while spread requires something to implement the iterator protocol, but we don't care about that, as it's what you should do anyway.

Should be easy to make this auto-fixable.

There's already a built-in ESLint rule called prefer-spread, but it's only concerned about .apply().

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions