Skip to content

Commit 7fb8b03

Browse files
authored
Document for-in restricted usage
airbnb#851 (comment)
1 parent 7816731 commit 7fb8b03

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,10 +1215,12 @@ Other Style Guides
12151215
## Iterators and Generators
12161216
12171217
<a name="iterators--nope"></a><a name="11.1"></a>
1218-
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html)
1218+
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) [`no-restricted-syntax`](http://eslint.org/docs/rules/no-restricted-syntax)
12191219
12201220
> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
12211221
1222+
> Use `map()` / `every()` / `filter()` / `find()` / `findIndex()` / `reduce()` / `some()` / ... to iterate over arrays, and `Object.keys()` / `Object.values()` / `Object.entries()` to produce arrays so you can iterate over objects.
1223+
12221224
```javascript
12231225
const numbers = [1, 2, 3, 4, 5];
12241226

0 commit comments

Comments
 (0)