JavaScripture
Contribute via GitHub Feedback

JavaScript Set : Object

Sets are a collection of Objects where each object can only appear once in the set.

Constructors

new Set() : Set

Creates an empty Set.

Example:

Run

Results:

 

new Set(iterable : Object) : Set

Creates a Set by iterating over iterable and adding each value to the Set.

Example:

Run

Results:

 

Instance Properties

size : Number

The number of value in this.

Example:

Run

Results:

 

Instance Methods

add(value : Object) : Set

Stores value in this. If value is already stored, there is no change to the Set. Returns this.

Example:

Run

Results:

 

clear() : undefined

Clears all values from this.

Example:

Run

Results:

 

delete(value : Object) : Boolean

Removes value* from this. Returns true if value was in this** before deleting it.

Example:

Run

Results:

 

entries() : Iterator

Returns an iterator of the items in this where the valuess of the iterator are of the form [value : Object, value : Object] (value is duplicated twice). See also keys() and values().

Example:

Run

Results:

 

forEach(callback : Function, [thisArg : Object]) : undefined
callback(value : Object, key : Object, set : Set) : undefined

Calls callback for each value in this. The Set passed to callback is the this of the call to forEach.

Example:

Run

Results:

 

has(value : Object) : Boolean

Returns true if the set contains value.

Example:

Run

Results:

 

keys() : Iterator

Same as values().

values() : Iterator

Returns an iterator of the values in this. The values function is also returned for this[Symbol.iterator] so you can iterate over this directly to get the values. See also entries() and keys().

Example:

Run

Results: