Set
Overview
The Set object lets you store unique values of any type, whether primitive values or object references. For more information see: Set (MDN).
Properties Summarized
Methods Summarized
The set() method adds or updates an entry in a Set object with a specified key and a value.
The entries() method returns a new iterator object that contains the [key, value] pairs for each element in the Set object in insertion order.
void
The forEach() method executes a provided function once for each value in the Set object, in insertion order.
The has() method returns a boolean indicating whether an element with the specified value exists in a Set object or not.
The keys() method returns a new iterator object that contains the keys for each element in the Set object in insertion order.
Properties Detailed
size
The size accessor property returns the number of elements in a Set object.
Type Number
Sample
Methods Detailed
add(value)
The set() method adds or updates an entry in a Set object with a specified key and a value.
Parameters
Object value ;
Returns: Set the Set itself
Sample
clear()
The clear() method removes all elements from a Set object.
Returns: void
Sample
delete(value)
The delete() method removes the specified element from a Set object by key.
Parameters
Object value ;
Returns: Boolean
Sample
entries()
The entries() method returns a new iterator object that contains the [key, value] pairs for each element in the Set object in insertion order. In this particular case, this iterator object is also an iterable, so the for-of loop can be used..
Returns: Iterator the iterator that can be used in for of loops
Sample
forEach(callback, thisArgument)
The forEach() method executes a provided function once for each value in the Set object, in insertion order.
Parameters
Returns: void
Sample
has(key)
The has() method returns a boolean indicating whether an element with the specified value exists in a Set object or not.
Parameters
Object key ;
Returns: Boolean
Sample
keys()
The keys() method returns a new iterator object that contains the keys for each element in the Set object in insertion order. In this particular case, this iterator object is also an iterable, so a for...of loop can be used.
Returns: Iterator the iterator that can be used in for of loops
Sample
values()
The values() method returns a new iterator object that contains the values for each element in the Set object in insertion order.
Returns: Iterator the iterator that can be used in for of loops
Sample
Last updated