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 1132225 of Set.prototype.delete()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Set/delete
  • Revision title: Set.prototype.delete()
  • Revision id: 1132225
  • Created:
  • Creator: stavarotti
  • Is current revision? Yes
  • Comment

Revision Content

{{JSRef}}

The delete() method removes the specified element from a Set object.

Syntax

mySet.delete(value);

Parameters

value
Required. The value of the element to remove from the Set object.

Return value

true if an element in the Set object has been removed successfully; otherwise false.

Examples

Using the delete method

var mySet = new Set();
mySet.add("foo");

mySet.delete("bar"); // Returns false. No "bar" element found to be deleted.
mySet.delete("foo"); // Returns true.  Successfully removed.

mySet.has("foo");    // Returns false. The "foo" element is no longer present.

Let's checkout below how to delete an Object from a Set.

 

var setObj = new Set(); // Create a New Set.

setObj.add({x:10,y:20}); // Add object in the set.

setObj.add({x:20,y:30}); // Add object in the set.


setObj.forEach(function(point){ if(point.x>10){setObj.delete(point)} }) // Delete an object from a Set.

Specifications

Specification Status Comment
{{SpecName('ES6', '#sec-set.prototype.delete', 'Set.prototype.delete')}} {{Spec2('ES6')}} Initial definition.
{{SpecName('ESDraft', '#sec-set.prototype.delete', 'Set.prototype.delete')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 38 {{CompatGeckoDesktop("13.0")}} 11 25 7.1
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} 38 {{CompatGeckoMobile("13.0")}} {{CompatNo}} {{CompatNo}} 8

See also

  • {{jsxref("Set")}}
  • {{jsxref("Set.prototype.clear()")}}

Revision Source

<div>{{JSRef}}</div>

<p>The <code><strong>delete()</strong></code> method removes the specified element from a <code>Set</code> object.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
<code><em>mySet</em>.delete(value);</code></pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt>value</dt>
 <dd>Required. The value of the element to remove from the <code>Set</code> object.</dd>
</dl>

<h3 id="Return_value">Return value</h3>

<p><code>true</code> if an element in the <code>Set</code> object has been removed successfully; otherwise <code>false</code>.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Using_the_delete_method">Using the <code>delete</code> method</h3>

<pre class="brush: js">
var mySet = new Set();
mySet.add("foo");

mySet.delete("bar"); // Returns false. No "bar" element found to be deleted.
mySet.delete("foo"); // Returns true.  Successfully removed.

mySet.has("foo");    // Returns false. The "foo" element is no longer present.
</pre>

<p>Let's checkout below how to delete an Object from a Set.</p>

<p>&nbsp;</p>

<pre class="brush: js">
var setObj = new Set(); // Create a New Set.

setObj.add({x:10,y:20}); // Add object in the set.

setObj.add({x:20,y:30}); // Add object in the set.


setObj.forEach(function(point){ if(point.x&gt;10){setObj.delete(point)} }) // Delete an object from a Set.</pre>

<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.delete', 'Set.prototype.delete')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-set.prototype.delete', 'Set.prototype.delete')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>&nbsp;</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.0")}}</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.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>8</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Set")}}</li>
 <li>{{jsxref("Set.prototype.clear()")}}</li>
</ul>
Revert to this revision