From 7fb8b037147b69bd8e759e93b3ca36a2916a1d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Malard?= Date: Wed, 6 Jul 2016 17:00:42 +0200 Subject: [PATCH] Document for-in restricted usage https://github.com/airbnb/javascript/issues/851#issuecomment-213834028 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21c9c858..e18dc2c7 100644 --- a/README.md +++ b/README.md @@ -1215,10 +1215,12 @@ Other Style Guides ## Iterators and Generators - - [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) + - [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) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. + > 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. + ```javascript const numbers = [1, 2, 3, 4, 5];