Day 31 of 100: Sets and Maps — Deduplication and Lookups
Day 31 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: JavaScript Fundamentals. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).
🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Sets store unique values. Maps store key-value pairs with any key type. Both solve real test problems arrays handle badly.
Contents
Set — Uniqueness for Free
const ids = [101, 102, 101, 103, 102];
const unique = [...new Set(ids)]; // [101, 102, 103]
// QA check: duplicate detection
const hasDuplicates = new Set(ids).size !== ids.length; // true
const seen = new Set();
seen.add('test-1');
seen.has('test-1'); // true
seen.size; // 1
🚀 Level Up Your Playwright
From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.
Map — Better Than Object for Dynamic Keys
const durations = new Map();
durations.set('login.spec.ts', 1240);
durations.set('checkout.spec.ts', 3580);
durations.get('login.spec.ts'); // 1240
durations.has('admin.spec.ts'); // false
// Iterate in insertion order
for (const [file, ms] of durations) {
console.log(`${file}: ${ms}ms`);
}
// Count failures by status — classic aggregation
const byStatus = new Map();
for (const s of [200, 404, 200, 500, 404]) {
byStatus.set(s, (byStatus.get(s) || 0) + 1);
}
// Map { 200 => 2, 404 => 2, 500 => 1 }
When to Use What
- Set: dedup lists, track visited/seen items
- Map: counters, lookups with non-string keys, ordered key-value data
- Plain object: fixed known keys (configs, payloads)
Tomorrow (Day 32): Optional chaining and nullish coalescing — crash-proof access.
🎓 Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
