Favorites

JavaScript Set.prototype.has() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Set.prototype.has()
JavaScript Set Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

const banned = new Set(['spam', 'scam']);
console.log(banned.has('spam'), banned.has('ham'));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee