# 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)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).

## Properties Summarized

| Type                                                     | Name          | Summary                                                                    |
| -------------------------------------------------------- | ------------- | -------------------------------------------------------------------------- |
| [Number](/reference/servoycore/dev-api/js-lib/number.md) | [size](#size) | The size accessor property returns the number of elements in a Set object. |

## Methods Summarized

| Type                                                         | Name                                                              | Summary                                                                                                                                         |
| ------------------------------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| [Set](/reference/servoycore/dev-api/js-lib/set.md)           | [add(value)](#add-value)                                          | The set() method adds or updates an entry in a Set object with a specified key and a value.                                                     |
| void                                                         | [clear()](#clear)                                                 | The clear() method removes all elements from a Set object.                                                                                      |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)   | [delete(value)](#delete-value)                                    | The delete() method removes the specified element from a Set object by key.                                                                     |
| [Iterator](/reference/servoycore/dev-api/js-lib/iterator.md) | [entries()](#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. |
| void                                                         | [forEach(callback, thisArgument)](#foreach-callback-thisargument) | The forEach() method executes a provided function once for each value in the Set object, in insertion order.                                    |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)   | [has(key)](#has-key)                                              | The has() method returns a boolean indicating whether an element with the specified value exists in a Set object or not.                        |
| [Iterator](/reference/servoycore/dev-api/js-lib/iterator.md) | [keys()](#keys)                                                   | The keys() method returns a new iterator object that contains the keys for each element in the Set object in insertion order.                   |
| [Iterator](/reference/servoycore/dev-api/js-lib/iterator.md) | [values()](#values)                                               | 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](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
set.size;
```

## 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](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [Set](/reference/servoycore/dev-api/js-lib/set.md) the Set itself

**Sample**

```js
set.add(value);
```

### clear()

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

**Returns:** void

**Sample**

```js
set.clear();
```

### delete(value)

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

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) True if the specified element was successfully removed from the Set; false otherwise.

**Sample**

```js
var success = set.delete(key);
```

### 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](/reference/servoycore/dev-api/js-lib/iterator.md) the iterator that can be used in for of loops

**Sample**

```js
for(var entry of set.entries()) {}
```

### forEach(callback, thisArgument)

The forEach() method executes a provided function once for each value in the Set object, in insertion order.

**Parameters**

* [Function](/reference/servoycore/dev-api/js-lib/function.md) **callback** ;
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **thisArgument** ;

**Returns:** void

**Sample**

```js
set.forEach(function(keyValuePair) {});
```

### 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](/reference/servoycore/dev-api/js-lib/object.md) **key** ;

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) True if the Set contains an element with the specified key; false otherwise.

**Sample**

```js
var containsKey = set.has(key);
```

### 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](/reference/servoycore/dev-api/js-lib/iterator.md) the iterator that can be used in for of loops

**Sample**

```js
var values = set.keys();
```

### 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](/reference/servoycore/dev-api/js-lib/iterator.md) the iterator that can be used in for of loops

**Sample**

```js
var values = set.values();
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/js-lib/set.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
