@putout/plugin-convert-for-each-to-for-of
v8.1.1
Published
šPutout plugin adds ability to convert 'forEach' to 'for...of'
Downloads
31,931
Maintainers
Readme
@putout/plugin-convert-for-each-to-for-of
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