Package Exports
- @putout/plugin-convert-for-in-to-for-of
- @putout/plugin-convert-for-in-to-for-of/lib/convert-for-in-to-for-of.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@putout/plugin-convert-for-in-to-for-of) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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