For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

Type
Name
Summary

The size accessor property returns the number of elements in a Set object.

Methods Summarized

Type
Name
Summary

The set() method adds or updates an entry in a Set object with a specified key and a value.

void

The clear() method removes all elements from a Set object.

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

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.

The values() method returns a new iterator object that contains the values 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

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

Returns: Boolean True if the specified element was successfully removed from the Set; false otherwise.

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

Returns: Boolean True if the Set contains an element with the specified key; false otherwise.

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

Was this helpful?