# js-set-map-lookups

The js-set-map-lookups rule recommends using a Set when code repeatedly checks array membership. It applies to repeated lookups, such as filtering items by ID.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 1064 repo stars
- Author: jarrodwatts
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/js-set-map-lookups.md
- Updated: 2026-01-21
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/js-set-map-lookups

## What it does

An `includes` call scans an array, so repeating that check means repeating a linear search. The rule shows how to build a `Set` from allowed values and test membership with `has`; its example filters `items` using `item.id`.

For Claude Code, place the rule at `.claude/rules/js-set-map-lookups.md`. The advice targets repeated checks; the example does not establish a need to convert an array used for a single lookup. The sample is JavaScript with TypeScript annotations.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/rules/js-set-map-lookups.md` — The paths frontmatter field limits the files

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### Cursor

**Manually: put the files in place**
- File: `.cursor/rules/js-set-map-lookups.mdc` — Frontmatter: description, globs, alwaysApply

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/js-set-map-lookups.instructions.md` — The applyTo field sets which files it applies to

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/js-set-map-lookups.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/js-set-map-lookups.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/js-set-map-lookups.md

## When to use it
- replace repeated array scans with set lookups
- check whether an item ID belongs to an allowed list
- filter `items` using a set of IDs

## Example prompts
- Review this code for repeated `includes` checks and switch them to a `Set`.
- Rewrite the `items` filter so it checks IDs with `Set.has`.
- Find repeated membership checks in this code and apply the rule.

## Similar
- [js-index-maps](https://affpapa.org/en/nevibecode/rules/js-index-maps.md) — rule · ★ 7191 repo stars
- [js-performance-patterns](https://affpapa.org/en/nevibecode/skills/js-performance-patterns.md) — skill · 716 installs
- [frontend-js-best-practices](https://affpapa.org/en/nevibecode/skills/frontend-js-best-practices.md) — skill · 341 installs
- [js-length-check-first](https://affpapa.org/en/nevibecode/rules/js-length-check-first.md) — rule · ★ 7191 repo stars
- [js-request-idle-callback](https://affpapa.org/en/nevibecode/rules/js-request-idle-callback.md) — rule · ★ 1216 repo stars
- [import-on-visibility](https://affpapa.org/en/nevibecode/skills/import-on-visibility.md) — skill · 1700 installs

From the same set: [jarrodwatts/claude-code-config](https://affpapa.org/en/nevibecode/by/jarrodwatts/claude-code-config.md) — 20 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
