@putout/plugin-convert-for-each-to-for-of

8.1.1 • Public • Published

@putout/plugin-convert-for-each-to-for-of NPM version

The forEach() method executes a provided function once for each array element.

The for...of statement creates a loop which invokes a custom iteration hook with statements to be executed for the value of each element of an array.

(c) MDN

🐊Putout plugin adds ability to convert forEach() to for...of. Complements @putout/plugin-convert-const-to-let. Merged to @putout/plugin-for-of.

Install

npm i @putout/plugin-convert-for-each-to-for-of -D

Rule

{
    "rules": {
        "convert-for-each-to-for-of": "on"
    }
}

Example of incorrect code

Object.keys(json).forEach((name) => {
    manage(name, json[name]);
});

[].forEach.call(arguments, (item) => {
    console.log(item);
});

Example of correct code

for (const name of Object.keys(json)) {
    manage(name, json[name]);
}

for (const name of arguments) {
    console.log(item);
}

License

MIT

/@putout/plugin-convert-for-each-to-for-of/

    Package Sidebar

    Install

    npm i @putout/plugin-convert-for-each-to-for-of

    Weekly Downloads

    10,742

    Version

    8.1.1

    License

    MIT

    Unpacked Size

    8.52 kB

    Total Files

    4

    Last publish

    Collaborators

    • coderaiser