This is an experimental technology, part of the Harmony (EcmaScript 6) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.
Summary
The Set.prototype property represents the prototype for the Set constructor.
Property attributes of Set.prototype |
|
|---|---|
| Writable | No |
| Enumerable | No |
| Configurable | No |
Description
Set instances inherit from 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
Setfunction by default. -
Set.prototype.size -
Returns the number of values in the
Setobject.
Methods
-
Set.prototype.add(value) -
Appends a new element with the given value to the
Setobject. -
Set.prototype.clear() -
Removes all elements from the
Setobject. -
Set.prototype.delete(value) -
Removes the element associated to the
value.Set.prototype.has(value)will returnfalseafterwards. -
Set.prototype.entries() -
Returns returns a new
Iteratorobject that contains an array of[value, value]for each element in theSetobject, in insertion order. This is kept similar to theMapobject, so that each entry has the same value for its key and value here. -
Set.prototype.forEach(callbackFn[, thisArg]) -
Calls callbackFn once for each value present in the
Setobject, in insertion order. If a thisArg parameter is provided to forEach, it will be used as thethisvalue for each callback. -
Set.prototype.has(value) -
Returns a boolean asserting whether an element is present with the given value in the
Setobject or not. -
Set.prototype.keys() -
Is the same function as the
values()function and returns a newIteratorobject that contains the values for each element in theSetobject in insertion order. -
Set.prototype.values() -
Returns returns a new
Iteratorobject that contains the values for each element in theSetobject in insertion order.
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript Language Specification 6th Edition (ECMA-262) | Draft | Initial definition. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 31 | 13.0 (13) | 11 | Not supported | Not supported |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | Not supported | ? | 13.0 (13) | Not supported | Not supported |
Not supported |
Chrome-specific notes
- The feature is available behind a preference. In
chrome://flags, activate the entry “Enable Experimental JavaScript”.