vue-doctor/performance/js-index-maps
Build a
Mapindexed by the search key before the loop for O(1) lookups
| Property | Value |
|---|---|
| Category | Performance |
| Default Severity | warning |
| Confidence | medium |
| Fixable | No |
| Engine | oxlint |
| Since | v1.0.0 |
| Frameworks | vue, nuxt |
| Test files | Not checked (which files) |
Why it matters
Build a Map indexed by the search key before the loop for O(1) lookups
How to fix
Review the finding and update the code according to best practices below.
Agent Guidance
Reported when a loop searches the same array on every iteration with a key-equality predicate (find(x => x.id === id)). Build a Map keyed by that field once before the loop and use map.get(key) instead. Searches whose array changes per iteration, or whose predicate is not a key comparison, are left alone.
Rule source: vue-doctor/performance/js-index-maps