@putout/plugin-convert-for-in-to-for-of
Version:
πPutout plugin adds ability to convert for-in to for-of
59 lines (43 loc) β’ 1.52 kB
Markdown
[]: https://img.shields.io/npm/v/@putout/plugin-convert-for-in-to-for-of.svg?style=flat&longCache=true
[]: https://npmjs.org/package/@putout/plugin-convert-for-in-to-for-of "npm"
> The [`for...in`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) statement iterates over all enumerable properties of an object that are keyed by strings.
>
> The [`for...of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/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**](https://github.com/coderaiser/putout) plugin adds ability to convert `for...in` to `for...of` loop. Merged to [`@putout/plugin-for-of`](https://www.npmjs.com/package/@putout/plugin-for-of).
```
npm i @putout/plugin-convert-for-in-to-for-of -D
```
```json
{
"rules": {
"convert-for-in-to-for-of/positive": "on",
"convert-for-in-to-for-of/negative": "on"
}
}
```
```js
for (const item in object) {
if (object.hasOwnProperty(item)) {
log(item);
}
}
for (const item in object) {
if (!object.hasOwnProperty(item))
continue;
log(item);
}
```
```js
for (const item of Object.keys(object)) {
log(item);
}
```
MIT