{{JSRef("Global_Objects", "Set")}} {{harmony()}}
Summary
The Set
.prototype
property represents the prototype for the {{jsxref("Set")}} constructor.
{{js_property_attributes(0,0,0)}}
Description
{{jsxref("Set")}} instances inherit from {{jsxref("Set.prototype")}}. You can use the constructor's prototype object to add properties or methods to all Set
instances.
Properties
-
Set.prototype.constructor
- Returns the function that created an instance's prototype. This is the {{jsxref("Set")}} function by default.
- {{jsxref("Set.prototype.size")}}
-
Returns the number of values in the
Set
object.
Methods
- {{jsxref("Set.add", "Set.prototype.add(value)")}}
-
Appends a new element with the given value to the
Set
object. Returns theSet
object. - {{jsxref("Set.prototype.clear()")}}
-
Removes all elements from the
Set
object. - {{jsxref("Set.delete", "Set.prototype.delete(value)")}}
-
Removes the element associated to the
value
.Set.prototype.has(value)
will returnfalse
afterwards. - {{jsxref("Set.prototype.entries()")}}
-
Returns a new
Iterator
object that contains an array of[value, value]
for each element in theSet
object, in insertion order. This is kept similar to theMap
object, so that each entry has the same value for its key and value here. - {{jsxref("Set.forEach", "Set.prototype.forEach(callbackFn[, thisArg])")}}
-
Calls
callbackFn
once for each value present in theSet
object, in insertion order. If athisArg
parameter is provided toforEach
, it will be used as thethis
value for each callback. - {{jsxref("Set.has", "Set.prototype.has(value)")}}
-
Returns a boolean asserting whether an element is present with the given value in the
Set
object or not. - {{jsxref("Set.prototype.keys()")}}
-
Is the same function as the
values()
function and returns a newIterator
object that contains the values for each element in theSet
object in insertion order. - {{jsxref("Set.prototype.values()")}}
-
Returns a new
Iterator
object that contains the values for each element in theSet
object in insertion order.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-set.prototype', 'Set.prototype')}} | {{Spec2('ES6')}} | Initial definition. |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 31 | {{ CompatGeckoDesktop("13") }} | 11 | {{ CompatNo() }} | {{ CompatNo() }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatNo() }} | {{ CompatUnknown() }} | {{ CompatGeckoMobile("13") }} | {{ CompatNo() }} | {{ CompatNo() }} |
{{ CompatNo() }} |
Chrome-specific notes
- The feature is available behind a preference. In
chrome://flags
, activate the entry “Enable Experimental JavaScript”.
See also
- {{jsxref("Map.prototype")}}