Array.includes is the tool everyone reaches for. Set.has sits one refactor away and is almost never used. I benchmarked both with a real run in Node.js 22, and the gap is not subtle. Full run in this Short: https://youtu.be/r2CVLAdLe5U
The test
A list of 100,000 items, and 1,000 lookups for values near the end of it. That is the worst case for includes: every lookup scans almost the whole list before finding its target. Set.has answers the same questions through a hash table.
The numbers
Array.includes: 83.46 ms. Set.has: 0.03 ms. Same 1,000 lookups, same data, same machine. That is a difference you can feel in a request handler, not a micro-optimization footnote.
The reason is the data structure, not cleverness. includes walks the array element by element, so 1,000 lookups each scanning ~100,000 items means ~100 million comparisons. Set.has hashes the target and jumps straight to it, so each lookup costs roughly the same no matter how big the set is.
The rule
If you build the list once and look things up many times, use a Set. Keep the array for order and iteration; build the Set for membership checks. For a handful of lookups against a small list, includes is fine and simpler. Not tested here: the cost of building the Set itself, other list sizes, or lookups for values near the front, where includes wins by doing almost nothing.
Watch the run
The real terminal output is in the Short: https://youtu.be/r2CVLAdLe5U (narration is AI-generated; the output is from a real run in Node.js 22).
Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.
