aleString)
    9. [ ` Object.prototype.toString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
    10. [ ` Object.prototype.valueOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

##  In this article

  * Description 
  * Constructor 
  * Static properties 
  * Instance properties 
  * Instance methods 
  * Examples 
  * Specifications 
  * Browser compatibility 
  * See also 

#  Set

##  Baseline  Widely available

This feature is well established and works across many devices and browser
versions. Itâs been available across browsers since  July 2015  .

  * [ Learn more ](/en-US/blog/baseline-evolution-on-mdn/)
  * See full compatibility 
  * [ Report feedback ](https://survey.alchemer.com/s3/7634825/MDN-baseline-feedback?page=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FSet&level=high)

The **` Set ` ** object lets you store unique values of any type, whether [
primitive values ](/en-US/docs/Glossary/Primitive) or object references.

##  Description

` Set ` objects are collections of values. A value in the set **may only occur
once** ; it is unique in the set's collection. You can iterate through the
elements of a set in insertion order. The _insertion order_ corresponds to the
order in which each element was inserted into the set by the [ ` add() `
](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add) method
successfully (that is, there wasn't an identical element already in the set
when ` add() ` was called).

The specification requires sets to be implemented "that, on average, provide
access times that are sublinear on the number of elements in the collection".
Therefore, it could be represented internally as a hash table (with O(1)
lookup), a search tree (with O(log(N)) lookup), or any other data structure,
as long as the complexity is better than O(N).

###  Value equality

Value equality is based on the [ SameValueZero ](/en-
US/docs/Web/JavaScript/Equality_comparisons_and_sameness#same-value-
zero_equality) algorithm. (It used to use [ SameValue ](/en-
US/docs/Web/JavaScript/Equality_comparisons_and_sameness#same-
value_equality_using_object.is) , which treated ` 0 ` and ` -0 ` as different.
Check  browser compatibility  .) This means [ ` NaN ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/NaN) is considered the same as
` NaN ` (even though ` NaN !== NaN ` ) and all other values are considered
equal according to the semantics of the ` === ` operator.

###  Performance

The [ ` has ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
method checks if a value is in the set, using an approach that is, on average,
quicker than testing most of the elements that have previously been added to
the set. In particular, it is, on average, faster than the [ `
Array.prototype.includes ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) method when an
array has a ` length ` equal to a set's ` size ` .

###  Set composition

The ` Set ` object provides some methods that allow you to compose sets like
you would with mathematical operations. These methods include:

Method  |  Return type  |  Mathematical equivalent  |  Venn diagram   
---|---|---|---  
[ ` A.difference(B) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference) |  ` Set ` |  A  â  B  A\setminus B  |  ![A Venn diagram where two circles overlap. The difference of A and B is the part of A that is not overlapping B.](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference/diagram.svg)  
[ ` A.intersection(B) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection) |  ` Set ` |  A  â©  B  A\cap B  |  ![A Venn diagram where two circles overlap. The intersection of A and B is the part where they overlap.](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection/diagram.svg)  
[ ` A.symmetricDifference(B) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference) |  `