no-for-in
💼 This rule is enabled in the ✅ recommended
config.
Disallows "for x in y" statements.
Rule Details​
"for in" loops iterate over the entire prototype chain, which is virtually never what you want. Use a "for of" loop or instead.
// Bad
const array = [1, 2, 3];
for (const element in array) {
}
// Good
const array = [1, 2, 3];
for (const element of array) {
}
// Bad
const object = { foo: "bar" };
for (const key in object) {
}
// Good
const object = { foo: "bar" };
for (const key of Object.keys(object)) {
}
Options​
This rule is not configurable.