This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The has() method of Set instances returns a boolean indicating whether the specified value exists in this Set or not.
const set = new Set([1, 2, 3, 4, 5]); console.log(set.has(1)); // Expected output: true console.log(set.has(5)); // Expected output: true console.log(set.has(6)); // Expected output: false
has(value)
valueThe value to test for presence in the Set object.
Returns true if the specified value exists in the Set object; otherwise false.
const mySet = new Set();
mySet.add("foo");
console.log(mySet.has("foo")); // true
console.log(mySet.has("bar")); // false
const set = new Set();
const obj = { key1: 1 };
set.add(obj);
console.log(set.has(obj)); // true
console.log(set.has({ key1: 1 })); // false, because they are different object references
console.log(set.add({ key1: 1 })); // now set contains 2 entries
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
has |
38 | 12 | 13 | 25 | 8 | 38 | 14 | 25 | 8 | 3.0 | 38 | 8 | 1.0.0 | 1.0 | 0.12.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has