hand sketched logo of electrons orbiting a nucleus

TIL: Use Set for Fast Array Lookup

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// big O of array lookup is O(n)
arr.includes(5); // true

// big O of set lookup is O(1)
const set = new Set(arr);

set.has(5); // true

We get constant lookup time because you can think of the Set being implemented with a hash table.