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).
backend ruleP2universalStack: javascript
arraysreadabilityperformance
Use find() instead of filter()[0] for the first match
When you want the first matching element, use find() rather than filter(...)[0]: it is clearer and stops at the first hit.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | const sub = user.subscriptions?.filter( |
| 2 | (s) => s.type === 'Email' && s.token === oldEmail |
| 3 | )[0]; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | const sub = user.subscriptions?.find( |
| 2 | (s) => s.type === 'Email' && s.token === oldEmail |
| 3 | ); |
Explanation (EN)
Objašnjenje (HR)