Loading...
const result = items.filter(
(x) => blocked.includes(x.id)
);const blockedSet = new Set(blocked);
const result = items.filter((x) => blockedSet.has(x.id));includes() scans blocked for every item; a Set lookup avoids that repeated scan.
set.has({ id: 1 }) returns false for an object that only looks the same.set.has() instead of array.includes() inside a loop.Set.has() faster than Array.includes()?For large or repeated checks, yes. has() is close to constant time on average, while includes() scans the array.
has() find NaN?Yes. Sets use SameValueZero, so new Set([NaN]).has(NaN) is true.