Skip to content
Guest
Learn JavaScript · Course Syllabus Show lessons
Data Structures & Modern Syntax · 9 min read · Beginner

Map, Set & .reduce() Aggregations

Deduplicate values instantly with Set, store fast key-value lookups in Map, and compute totals or grouped summaries with .reduce().

What you'll learn

  • Remove duplicates and check membership in O(1) time with Set
  • Use Map for dynamic key-value collections with clean .get()/.set()/.size APIs
  • Summarize arrays into totals or grouped objects with .reduce()

Plain arrays and objects are great, but JavaScript also includes built-in Set and Map collections plus .reduce() for clean data transformations.

Instant Deduplication with Set

const tags = ['html', 'css', 'html', 'js', 'css'];
const unique = [...new Set(tags)]; // ['html', 'css', 'js']

Computing Totals with .reduce()

const minutes = [6, 8, 9, 12];
const total = minutes.reduce((sum, m) => sum + m, 0); // 35

Fill-in-the-Blank Exercise

Set Deduplication & .reduce()

Create a Set of unique tags and sum lesson durations with .reduce().

const unique = [...new (tags)];
const totalMins = lessons.((acc, l) => acc + l.mins, 0);

Try It Yourself

Set, Map & .reduce() in Action
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. What does `new Set([1, 2, 2, 3, 3]).size` return?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind