complete/no-for-in
💼 This rule is enabled in the ✅ recommended config.
📝 Disallows “for x in y” statements.
Rule Details
Section titled “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.
// Badconst array = [1, 2, 3];for (const element in array) {}
// Goodconst array = [1, 2, 3];for (const element of array) {}
// Badconst object = { foo: "bar" };for (const key in object) {}
// Goodconst object = { foo: "bar" };for (const key of Object.keys(object)) {}Options
Section titled “Options”This rule is not configurable.
