JavaScript Set.prototype.has() Method
The has() method checks whether a value is in a Set. It's much faster than searching an array.
Description
The has() method returns whether a value is in the set. Lookups are fast regardless of the set's size, which makes sets ideal for things like checking if an item has already been seen.
It's much faster than Array.prototype.includes() for large collections, because a set doesn't need to look at each value in turn. Converting an array to a set once, then calling has() many times, is a common optimization.
Values are compared with the SameValueZero algorithm, so NaN matches NaN, but two separate objects with the same contents are different values.
Syntax
set.has(value)Parameters
- valueThe value to look for.
Return Value
true if the value is in the set, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the Set.prototype.has() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





