Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 703121 of Set.prototype

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Set/prototype
  • Revision title: Set.prototype
  • Revision id: 703121
  • Created:
  • Creator: BlindWanderer
  • Is current revision? No
  • Comment

Revision Content

{{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 the Set 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 and returns the value that Set.prototype.has(value) would have previously returned. Set.prototype.has(value) will return false afterwards.
{{jsxref("Set.prototype.entries()")}}
Returns a new Iterator object that contains an array of [value, value] for each element in the Set object, in insertion order. This is kept similar to the Map 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 the Set object, in insertion order. If a thisArg parameter is provided to forEach, it will be used as the this 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 new Iterator object that contains the values for each element in the Set object in insertion order.
{{jsxref("Set.prototype.values()")}}
Returns a new Iterator object that contains the values for each element in the Set object in insertion order.
{{jsxref("Set.prototype.@@iterator()", "Set.prototype[@@iterator]()")}}
Returns a new Iterator object that contains the values for each element in the Set 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 38 {{ CompatGeckoDesktop("13") }} 11 25 7.1
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} 38 {{ CompatGeckoMobile("13") }} {{ CompatNo() }} {{ CompatNo() }}

iOS 8

See also

  • {{jsxref("Map.prototype")}}

Revision Source

<div>
 {{JSRef("Global_Objects", "Set")}} {{harmony()}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code><strong>Set</strong></code><strong><code>.prototype</code></strong> property represents the prototype for the {{jsxref("Set")}} constructor.</p>
<div>
 {{js_property_attributes(0,0,0)}}</div>
<h2 id="Description" name="Description">Description</h2>
<p>{{jsxref("Set")}} instances inherit from {{jsxref("Set.prototype")}}. You can use the constructor's prototype object to add properties or methods to all <code>Set</code> instances.</p>
<h2 id="Properties">Properties</h2>
<dl>
 <dt>
  <code>Set.prototype.constructor</code></dt>
 <dd>
  Returns the function that created an instance's prototype. This is the {{jsxref("Set")}} function by default.</dd>
 <dt>
  {{jsxref("Set.prototype.size")}}</dt>
 <dd>
  Returns the number of values in the <code>Set</code> object.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<dl>
 <dt>
  {{jsxref("Set.add", "Set.prototype.add(value)")}}</dt>
 <dd>
  Appends a new element with the given value to the <code>Set</code> object. Returns the <code>Set</code> object.</dd>
 <dt>
  {{jsxref("Set.prototype.clear()")}}</dt>
 <dd>
  Removes all elements from the <code>Set</code> object.</dd>
 <dt>
  {{jsxref("Set.delete", "Set.prototype.delete(value)")}}</dt>
 <dd>
  Removes the element associated to the <code>value</code> and returns the value that <code>Set.prototype.has(value)</code> would have previously returned. <code>Set.prototype.has(value)</code> will return <code>false</code> afterwards.</dd>
 <dt>
  {{jsxref("Set.prototype.entries()")}}</dt>
 <dd>
  Returns a new <code>Iterator</code> object that contains<strong> an array of <code>[value, value]</code></strong> for each element in the <code>Set</code> object, in insertion order. This is kept similar to the <code>Map</code> object, so that each entry has the same value for its <em>key</em> and <em>value</em> here.</dd>
 <dt>
  {{jsxref("Set.forEach", "Set.prototype.forEach(callbackFn[, thisArg])")}}</dt>
 <dd>
  Calls <code>callbackFn</code> once for each value present in the <code>Set</code> object, in insertion order. If a <code>thisArg</code> parameter is provided to <code>forEach</code>, it will be used as the <code>this</code> value for each callback.</dd>
 <dt>
  {{jsxref("Set.has", "Set.prototype.has(value)")}}</dt>
 <dd>
  Returns a boolean asserting whether an element is present with the given value in the <code>Set</code> object or not.</dd>
 <dt>
  {{jsxref("Set.prototype.keys()")}}</dt>
 <dd>
  Is the same function as the <strong><code>values()</code></strong> function and returns a new <code>Iterator</code> object that contains the values for each element in the <code>Set</code> object in insertion order.</dd>
 <dt>
  {{jsxref("Set.prototype.values()")}}</dt>
 <dd>
  Returns a new <code>Iterator</code> object that contains the <strong>values</strong> for each element in the <code>Set</code> object in insertion order.</dd>
 <dt>
  {{jsxref("Set.prototype.@@iterator()", "Set.prototype[@@iterator]()")}}</dt>
 <dd>
  Returns a new <code>Iterator</code> object that contains the <strong>values</strong> for each element in the <code>Set</code> object in insertion order.</dd>
</dl>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-set.prototype', 'Set.prototype')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>38</td>
    <td>{{ CompatGeckoDesktop("13") }}</td>
    <td>11</td>
    <td>25</td>
    <td>7.1</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Chrome for Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatNo() }}</td>
    <td>38</td>
    <td>{{ CompatGeckoMobile("13") }}</td>
    <td>{{ CompatNo() }}</td>
    <td>{{ CompatNo() }}</td>
    <td>
     <p>iOS 8</p>
    </td>
   </tr>
  </tbody>
 </table>
</div>
<h3 id="See_also"><span style="font-size: 2.142857142857143rem; font-weight: 700; letter-spacing: -1px; line-height: 30px;">See also</span></h3>
<ul>
 <li>{{jsxref("Map.prototype")}}</li>
</ul>
Revert to this revision