You can't compare references like arrays and objects for equality (you can compare values, though).

The way you're doing it, you're checking against a different reference, even though the values appear to be the same.

Do something like this:

var a = new Set();
var b = [1];

a.add(b);

a.has(b); // => true

Take a look at MDN's Equality comparisons and sameness.

So it might be that the Set .has() is using == for comparing equality (not sure though)

Not necessarily. [1] === [1] (using the strict equality operator) also returns false.

Is there a .contains() method for Set() in JS like Java has?

Not in the way you're imagining it. You can do some sort of deep comparison, as mentioned in the first link in this answer.

Answer from Josh Beam on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › has
Set.prototype.has() - JavaScript - MDN Web Docs
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 · Set · Set.prototype.add() Set.prototype.delete() Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Sep 22, 2025 by MDN contributors.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set
Set - JavaScript - MDN Web Docs
August 13, 2026 - Returns a new iterator object that contains an array of [value, value] for each element in the Set object, in insertion order.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › entries
Set.prototype.entries() - JavaScript - MDN Web Docs
July 20, 2025 - The entries() method of Set instances returns a new set iterator object that contains an array of [value, value] for each element in this set, in insertion order. For Set objects there is no key like in Map objects. However, to keep the API similar to the Map object, each entry has the same ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › values
Set.prototype.values() - JavaScript - MDN Web Docs - Mozilla
The values() method of Set instances returns a new set iterator object that contains the values for each element in this set in insertion order.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › isSubsetOf
Set.prototype.isSubsetOf() - JavaScript - MDN Web Docs
May 22, 2026 - The isSubsetOf() method of Set instances takes a set and returns a boolean indicating if all elements of this set are in the given set.
Find elsewhere
🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › web › javascript › reference › functions › set › index.md
content/files/en-us/web/javascript/reference/functions/set/index.md at main · mdn/content
The **`set`** syntax binds an object property to a function to be called when there is an attempt to set that property. It can also be used in [classes](/en-US/docs/Web/JavaScript/Reference/Classes).
Author: mdn
🌐
IGM
www-igm.univ-mlv.fr › ~forax › MDN › developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › has.html
Set.prototype.has() - JavaScript | MDN
August 9, 2023 - const mySet = new Set(); mySet.add("foo"); console.log(mySet.has("foo")); // true console.log(mySet.has("bar")); // false const set1 = new Set(); const obj1 = { key1: 1 }; set1.add(obj1); console.log(set1.has(obj1)); // true console.log(set1.has({ key1: 1 })); // false, because they are different object references console.log(set1.add({ key1: 1 })); // now set1 contains 2 entries ... YesNoLearn how to contribute. This page was last modified on Aug 9, 2023 by MDN contributors.
🌐
Bsmth
bsmth.de › mdn-javascript-set-methods
New JavaScript Set methods - Brian Smith
June 26, 2024 - The JavaScript Set object has new methods that now have cross-browser support, so let's have a look at what they can do and why they're interesting.
🌐
Can I Use
caniuse.com › mdn-javascript_builtins_set_has
JavaScript built-in: Set: has | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › intersection
Set.prototype.intersection() - JavaScript - MDN Web Docs
May 22, 2026 - The intersection() method of Set instances takes a set and returns a new set containing elements in both this set and the given set.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-set-has-method
JavaScript Set has() Method - GeeksforGeeks
June 4, 2026 - The Set.has() method in JavaScript is used to check whether an element with a specified value exists in a Set or not.
🌐
Mozilla
developer.mozilla.org › en-US › blog › javascript-set-methods
New JavaScript Set methods - MDN Web Docs - Mozilla
June 24, 2024 - We're using the HTML textContent of each list item so we have sets of strings, but you can see how this can be powerful if we consider that sets can contain data types like arrays or objects.
🌐
Unibo
lia.disi.unibo.it › materiale › JS › developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set.html
Set - JavaScript | MDN
April 12, 2015 - Returns a boolean asserting whether an element is present with the given value in the Set object or not. ... Is the same function as the values() function and returns a new Iterator object that contains the values for each element in the Set ...
🌐
W3Schools
w3schools.com › js › js_sets.asp
JavaScript Sets
A JavaScript Set is a collection of unique values.
🌐
W3Schools
w3schools.com › jsref › jsref_set_has.asp
JavaScript Set has() Method
The has() method returns true if a specified value exists in a set.
🌐
MDN Web Docs
devdoc.net › web › developer.mozilla.org › en-US › docs › JavaScript › Reference › Global_Objects › Set.html
Set - JavaScript | MDN - Developer's Documentation Collections
July 11, 2017 - Returns a boolean asserting whether an element is present with the given value in the Set object or not. ... Is the same function as the values() function and returns a new Iterator object that contains the values for each element in the Set object in insertion order.