Skip to content

Make automatic refactoring between for...of and forEach in JavaScript #28

Open

Description

@unv-unv

I was transitioning a lot of "for...of" cycles into forEach cycles to implement IE12 support. And it is very easy from automatic point of view. So if you implement this transition (forward and backward) as an automatic option on Alt+Enter, it would be good.

for (let element of array) { ... }

array.forEach(function (element) { ... });

Activity

  1. unv-unv commented on Jun 17, 2020

    @unv-unv
    ContributorAuthor

    Though I need to say that not every forEach may be translated to "for...of". There may be additional parameters in forEach function:
    https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

    Still, there may be a more complex transition:

    for (const [index, value] of array.entries()) { ... }

    array.forEach(function (value, index) { ... }

  2. self-assigned this
    on Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions