js set map lookups
本地来源:Knowledge/World/项目/Practice/Claude-Skills/vercel-react-best-practices/rules/js-set-map-lookups.md
title: Use Set/Map for O(1) Lookups impact: LOW-MEDIUM impactDescription: O(n) to O(1) tags: javascript, set, map, data-structures, performance
Use Set/Map for O(1) Lookups
Convert arrays to Set/Map for repeated membership checks.
Incorrect (O(n) per check):
const allowedIds = ['a', 'b', 'c', ...]
items.filter(item => allowedIds.includes(item.id))
Correct (O(1) per check):
const allowedIds = new Set(['a', 'b', 'c', ...])
items.filter(item => allowedIds.has(item.id))
本文档为站内渲染。原始文件本地路径:saas/source/knowledge-world/Knowledge-World-项目-Practice-Claude-Skills-vercel-react-best--c628f0.md(仅本地保留,不入库不部署)