Data MasteryThursday, January 29, 2026

Maps & Sets

Modern ES6 data structures.

Advertisement

Support JS Mastery Path by checking out our sponsors.

ES6 introduced Map and Set to solve limitations with plain Objects and Arrays.

Set (Unique Values)

The fastest way to remove duplicates.

const emails = ["a@a.com", "b@b.com", "a@a.com"];
const uniqueEmails = [...new Set(emails)];
console.log(uniqueEmails); // ["a@a.com", "b@b.com"]

Map (Better Key-Value)

Why Map instead of Object?
  • Keys can be ANY type (Objects, Functions), not just Strings.
  • Preserves insertion order.
  • Has a built-in .size property (No need for Object.keys().length).
const cache = new Map();
const user = { id: 1 };

// Using an object as a key!
cache.set(user, "User Data");

console.log(cache.get(user)); // "User Data"
Advertisement

Support JS Mastery Path by checking out our sponsors.