# Map

## Overview

The Map object holds key-value pairs and remembers the original insertion order of the keys.\
Any value (both objects and primitive values) may be used as either a key or a value.

For more information see: [Map (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).

## 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 Map object. |

## Methods Summarized

| Type                                                         | Name                                                              | Summary                                                                                                                                         |
| ------------------------------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| void                                                         | [clear()](#clear)                                                 | The clear() method removes all elements from a Map object.                                                                                      |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)   | [delete(key)](#delete-key)                                        | The delete() method removes the specified element from a Map 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 Map object in insertion order. |
| void                                                         | [forEach(callback, thisArgument)](#foreach-callback-thisargument) | The forEach() method executes a provided function once for each value in the Map object, in insertion order.                                    |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)     | [get(key)](#get-key)                                              | The get() method returns a specified element from a Map object.                                                                                 |
| [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 key exists in a Map 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 Map object in insertion order.                   |
| [Map](/reference/servoycore/dev-api/js-lib/map.md)           | [set(key, value)](#set-key-value)                                 | The set() method adds or updates an entry in a Map object with a specified key and a value.                                                     |
| [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 Map object in insertion order.               |

## Properties Detailed

### size

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

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
map.size;
```

## Methods Detailed

### clear()

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

**Returns:** void

**Sample**

```js
map.clear();
```

### delete(key)

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

**Parameters**

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

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

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

### entries()

The entries() method returns a new iterator object that contains the \[key, value] pairs for each element in the Map 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 map.entries()) {}
```

### forEach(callback, thisArgument)

The forEach() method executes a provided function once for each value in the Map 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
map.forEach(function(keyValuePair) {});
```

### get(key)

The get() method returns a specified element from a Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map object.

**Parameters**

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

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

**Sample**

```js
var value = map.get(key);
```

### has(key)

The has() method returns a boolean indicating whether an element with the specified key exists in a Map object or not.

**Parameters**

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

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

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

### keys()

The keys() method returns a new iterator object that contains the keys for each element in the Map 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 = map.keys();
```

### set(key, value)

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

**Parameters**

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

**Returns:** [Map](/reference/servoycore/dev-api/js-lib/map.md)

**Sample**

```js
map.set(keyObject, value);
```

### values()

The values() method returns a new iterator object that contains the values for each element in the Map 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 = map.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/map.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.
