---
title: "js set map lookups"
description: "Convert arrays to Set/Map for repeated membership checks."
type: skill
canonical_url: https://claudary.paisolsolutions.com/skills/js-set-map-lookups
source: "Claudary"
difficulty: intermediate
author: "Claude Code Knowledge Pack"
date: 2026-07-10T11:30:22.788Z
license: CC-BY-4.0
attribution: "js set map lookups — Claudary (https://claudary.paisolsolutions.com/skills/js-set-map-lookups)"
---

# js set map lookups
Convert arrays to Set/Map for repeated membership checks.

## Overview

---
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):**

```typescript
const allowedIds = ['a', 'b', 'c', ...]
items.filter(item => allowedIds.includes(item.id))
```

**Correct (O(1) per check):**

```typescript
const allowedIds = new Set(['a', 'b', 'c', ...])
items.filter(item => allowedIds.has(item.id))
```

---

Source: [Claudary](https://claudary.paisolsolutions.com/skills/js-set-map-lookups) · https://claudary.paisolsolutions.com
