@putout/plugin-convert-for-in-to-for-of
v2.0.1
Published
šPutout plugin adds ability to convert for-in to for-of
Downloads
34,661
Maintainers
Readme
@putout/plugin-convert-for-in-to-for-of
The
for...in
statement iterates over all enumerable properties of an object that are keyed by strings.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 for...in
to for...of
loop. Merged to @putout/plugin-for-of
.
Install
npm i @putout/plugin-convert-for-in-to-for-of -D
Rule
{
"rules": {
"convert-for-in-to-for-of/positive": "on",
"convert-for-in-to-for-of/negative": "on"
}
}
ā Example of incorrect code
for (const item in object) {
if (object.hasOwnProperty(item)) {
log(item);
}
}
for (const item in object) {
if (!object.hasOwnProperty(item))
continue;
log(item);
}
ā Example of correct code
for (const item of Object.keys(object)) {
log(item);
}
License
MIT