Learn JavaScript

Lesson 4 of 9 · Map, Set, WeakMap, Iterators, Generators and Regular Expressions

Module 16 · Map, Set, WeakMap, Iterators, Generators and Regular Expressions

When to Use Which: Map or Object, Set or Array, WeakMap or Map, Generator or Array, Regex or String Methods

ProReading

Every tool in this module has a neighbour that does almost the same job. A Map sits next to the plain object, a Set next to the array, and a WeakMap next to the Map. A generator sits next to an array you build first, and a regex next to split and includes. Picking the wrong one rarely crashes. It makes code slow, leaky or hard to read, and nobody notices until the data grows.

Checking what this lesson needs for you…

What is inside When to Use Which: Map or Object, Set or Array, WeakMap or Map, Generator or Array, Regex or String Methods

  1. Map, object or array
  2. Set or an array's includes
  3. WeakMap or Map
  4. A generator or an array
  5. A regex, string methods or a parser
  6. The decision on one page