Data MasterySaturday, January 24, 2026

Maps & Sets

Modern ES6 data structures.

Advertisement

Support JS Fruggal 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 = ["[email protected]", "[email protected]", "[email protected]"];
const uniqueEmails = [...new Set(emails)];
console.log(uniqueEmails); // ["[email protected]", "[email protected]"]

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 Fruggal by checking out our sponsors.