Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP1universalStack: javascript
javascriptiterationarraysobjectsbug
Iterate arrays with array methods, not for...in
Use forEach/for...of for arrays; reserve for...in for enumerating object properties.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | for (const key in myArray) { |
| 2 | doSomething(myArray[key]); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | myArray.forEach(item => doSomething(item)); |
| 2 | // for...in stays for plain objects: |
| 3 | Object.keys(targeting).forEach(key => doSomething(targeting[key])); |
Explanation (EN)
Objašnjenje (HR)