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 ·
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-set-has-method
JavaScript Set has() Method - GeeksforGeeks
June 4, 2026 - // Create a new set using Set() constructor let myset = new Set(); // Append new elements to the // set using add() method myset.add("Chicago"); myset.add("California"); myset.add("London"); // As London exists in the set, // it will return true console.log(myset.has("London")); // As Manchester does not exist in the // set, it will return false console.log(myset.has("Manchester"));
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript set contains | example
JavaScript Set contains | Example - Tutorial - By EyeHunts
August 10, 2022 - const mySet = new Set(); mySet.add('foo'); mySet.has('foo'); // returns true mySet.has('bar'); // returns false const set1 = new Set(); const obj1 = {'key1': 1}; set1.add(obj1); set1.has(obj1); // returns true set1.has({'key1': 1}); // returns false because they are different object references set1.add({'key1': 1}); // now set1 contains 2 entries
🌐
DEV Community
dev.to › programminginblood › why-sethas-is-faster-than-arrayincludes-for-finding-items-4hh
Why Set.has() is Faster Than Array.includes() for Finding Items - DEV Community
November 1, 2024 - When you use Set.has(), JavaScript can find the item in one direct operation, no matter how many items are in the set. For example, while checking if a value is in a set that contains a million, the time consumed by Set.has() will be precisely the same as checking ten.
🌐
TutorialKart
tutorialkart.com › javascript › javascript-check-if-set-contains-specific-element
How to check if Set contains Specific Element in JavaScript?
October 1, 2021 - To check if this Set contains a specific element in JavaScript, call has() method on this set and pass the element, to search for, as argument to it.
🌐
W3Schools
w3schools.com › JSREF › jsref_set_has.asp
JavaScript Set has() Method
❮ Previous JavaScript Set Reference Next ❯ · // Create a Set const letters = new Set(["a","b","c"]); // Does the Set contain "d"? answer = letters.has("d"); Try it Yourself » · The has() method returns true if a specified value exists in a set. set.has(value) The Set clear() Method ·
🌐
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
🌐
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
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.
🌐
Bjornharrtell
bjornharrtell.github.io › javascript.util › doc › javascript.util.Set.html
Class: Set
Ensures that this collection contains the specified element (optional operation). Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
🌐
DEV Community
dev.to › arnaud › using-array-prototype-includes-vs-set-prototype-has-to-filter-arrays-41fg
Using Array.prototype.includes() vs Set.prototype.has() to filter arrays - DEV Community
July 2, 2020 - const valuesToKeep = [2, 4]; const valuesToTest = [1, 2, 3, 4]; const setToKeep = new Set(valuesToKeep); const values = valuesToTest.filter((n) => setToKeep.has(n)); // [2, 4] My comment didn't sit well with me because saying "hey this will perform OK because the data is a certain way" is not a good idea: the data may change, or maybe I'm just wrong. So I decided to put this to test. I'm going to generate two arrays containing random integers: an array of values to keep, and an array of values to test.
🌐
W3Schools
w3schools.com › js › js_set_methods.asp
JavaScript Set Methods
// Create a Set const letters = new Set(["a","b","c"]); // Does the Set contain "d"? answer = letters.has("d"); Try it Yourself » ·
🌐
Collectionsjs
collectionsjs.com › set
Set - Collections for JavaScript
Returns a new collection of the same type containing all the values of itself and the values of any number of other iterable collections in order.
🌐
Scaler
scaler.com › home › topics › set in javascript
Set in JavaScript - Scaler Topics
December 19, 2022 - SubSet A set is said to be a subset of another set if the other set contains all elements of this set. Suppose we have two sets, setA, and setB. In this example, we shall see how to implement the subset operation in set in javascript.
🌐
Medium
medium.com › @amirakhaled2027 › javascript-set-methods-95e94892703d
JavaScript Set Methods. A set in JavaScript is a collection of… | by Amira Khaled | Medium
June 11, 2024 - A set in JavaScript is a collection of unique values. It means that no value can appear more than once within a set. Sets are often used…
🌐
Curiosum
curiosum.com › home › blog › today i learned › how to check if a set contains exact values with jest in js?
Check if a set contains exact values with Jest in JS | Curiosum
September 9, 2025 - You can convert set to array and check for inclusion (elements ordering does not matter), but then you also need to check if sets have equal sizes: expect([...foundPossibleMoves]).toEqual( expect.arrayContaining([...possibleMoves]), ); expect(foundPossibleMoves.size).toEqual(possibleMoves.size); Fortunately, jest-extended package contains matcher named toIncludeSameMembers that does the both: