Skip to main content

JavaScript Map & Set

5 lessonsAbout 30 minutesAdvanced

This part of the JavaScript Tutorial runs from JavaScript Map through to JavaScript WeakMap and WeakSet. There are 5 lessons here, and working through them takes about 30 minutes at a steady pace.

It follows on from JavaScript Errors, so finish that first if you have not already — the examples below assume you are comfortable with it.

Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.

  1. 1JavaScript MapA Map stores key and value pairs where the key can be any type.
  2. 2JavaScript Map MethodsMap methods let you loop over entries and convert to and from other structures.
  3. 3JavaScript SetA Set stores unique values, automatically ignoring duplicates.
  4. 4JavaScript Set OperationsSets can be combined to find values in common, or values in one but not the other.
  5. 5JavaScript WeakMap and WeakSetWeakMap and WeakSet hold objects without preventing them being cleaned up.