---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md
  - https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Collection.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/dev/jsapi-v2-1/doc/en/llms.txt

# Collection

Extends [ICollection](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICollection.md), [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md).

Basic implementation of an object collection on the map.

[Constructor](#constructor-summary) | [Fields](#properties-summary) | [Events](#events-summary) | [Methods](#methods-summary)

## Constructor {#constructor-summary}

```javascript
Collection([options])
```

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`options`](#param-options) | — | Type: Object

Collection options. ||
|#


## Fields {#properties-summary}

#|
|| **Name** | **Type** | **Description** ||
|| [events](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events) | [IEventManager](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventManager.md)| Event manager.

Inherited from [IEventEmitter](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events). ||
|| [options](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options) | [IOptionManager](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IOptionManager.md)| Options manager.

Inherited from [ICustomizable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options). ||
|#

## Events {#events-summary}

#|
|| **Name** | **Description** ||
|| [add](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#event-add)| A child object was added. Instance of the [Event](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md) class. Names of fields that are available via the [Event.get](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- child - Child element that was added. ||
|| [mapchange](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md#event-mapchange)| Map reference changed. Data fields: 
- oldMap - Old map.
- newMap - New map.

Inherited from [IParentOnMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md#event-mapchange). ||
|| [optionschange](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange)| Change to the object options.

Inherited from [ICustomizable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange). ||
|| [parentchange](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChild.md#event-parentchange)| The parent object reference changed.

Data fields:

- oldParent - Old parent.
- newParent - New parent.

Inherited from [IChild](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChild.md#event-parentchange). ||
|| [remove](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#event-remove)| A child object was deleted. Instance of the [Event](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md) class. Names of fields that are available via the [Event.get](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- child - Child element that was deleted. ||
|#

## Methods {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [add](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#add)([child](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#add-param-child)) | [Collection](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md)
| Adds an item to the collection. ||
|| [each](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#each)([callback](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#each-param-callback)[, [context](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#each-param-context)]) | [Collection](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md)
| Calls a handler function for all the items in the collection. ||
|| [filter](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#filter)([filterFunction](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#filter-param-filterFunction)) | Object[]
| Calls a filter function for all the items in the collection. When the filter returns a non-zero value, the collection item goes in the final array. ||
|| [get](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#get)([index](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#get-param-index)) | Object
| Returns a collection item, or null if the number is outside of the range for the collection's numbers. ||
|| [getAll](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#getAll)() | Object[]
| Returns an array with all the collection items. ||
|| [getIterator](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#getIterator)() | [IIterator](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IIterator.md)
| Returns an iterator for selecting collection items. ||
|| [getLength](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#getLength)() | Number
| Returns the number of items in the collection. ||
|| [getMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#getMap)() | [Map](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map.md)
| Returns the map that the collection item belongs to.

Inherited from [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#getMap). ||
|| [getParent](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#getParent)() | [IParentOnMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md)
| Returns parent object.

Inherited from [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#getParent). ||
|| [indexOf](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#indexOf)([childToFind](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#indexOf-param-childToFind)) | Number
| Returns the sequential number of the object in the collection, or -1 if the object was not found. ||
|| [onAddToMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onAddToMap)([map](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onAddToMap-param-map)) | | Function that is called when adding an element to the map. To perform additional actions when adding the object to the map, redefine this function.

Inherited from [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onAddToMap). ||
|| [onRemoveFromMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onRemoveFromMap)([oldMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onRemoveFromMap-param-oldMap)) | | Function that is called when deleting an element from the map. To perform additional actions when deleting the object from the map, redefine this function.

Inherited from [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onRemoveFromMap). ||
|| [remove](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#remove)([child](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#remove-param-child)) | [Collection](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md)
| Deletes an item from a collection. ||
|| [removeAll](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md#removeAll)() | [Collection](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Collection.md)
| Deletes all the items from a collection. ||
|| [setParent](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#setParent)([parent](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#setParent-param-parent)) | [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md)
| Sets the parent for the selected item in a collection.

Inherited from [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#setParent). ||
|#

## Events details {#event_detail}

### add {#add}

A child object was added. Instance of the [Event](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md) class. Names of fields that are available via the [Event.get](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- child - Child element that was added.

### remove {#remove}

A child object was deleted. Instance of the [Event](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md) class. Names of fields that are available via the [Event.get](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- child - Child element that was deleted.

## Methods details {#method_detail}

### add {#add}

```javascript
{Collection} add(child)
```

Adds an item to the collection.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`child`](#add-param-child)[*](*star) | — | Type: [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md)

Element to add. ||
|#

\* Mandatory parameter/option.

### each {#each}

```javascript
{Collection} each(callback[, context])
```

Calls a handler function for all the items in the collection.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`callback`](#each-param-callback)[*](*star) | — | Type: Function

Handler function. Receives a collection item as input. If the function returns the value "false," processing stops. ||
|| [`context`](#each-param-context) | — | Type: Object

Context of the invoked function. ||
|#

\* Mandatory parameter/option.

### filter {#filter}

```javascript
{Object[]} filter(filterFunction)
```

Calls a filter function for all the items in the collection. When the filter returns a non-zero value, the collection item goes in the final array.

**Returns** an array of items that were selected.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`filterFunction`](#filter-param-filterFunction)[*](*star) | — | Type: Function

Function that works as a filter for the collection's objects. It takes an item from the collection as the first parameter. It should return a boolean value. ||
|#

\* Mandatory parameter/option.

### get {#get}

```javascript
{Object} get(index)
```

**Returns** a collection item, or null if the number is outside of the range for the collection's numbers.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#get-param-index)[*](*star) | — | Type: Number

The sequential number of the item in the collection. ||
|#

\* Mandatory parameter/option.

### getAll {#getAll}

```javascript
{Object[]} getAll()
```

**Returns** an array with all the collection items.

### getIterator {#getIterator}

```javascript
{IIterator} getIterator()
```

**Returns** an iterator for selecting collection items.

### getLength {#getLength}

```javascript
{Number} getLength()
```

**Returns** the number of items in the collection.

### indexOf {#indexOf}

```javascript
{Number} indexOf(childToFind)
```

**Returns** the sequential number of the object in the collection, or -1 if the object was not found.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`childToFind`](#indexOf-param-childToFind)[*](*star) | — | Type: Object

The required object. ||
|#

\* Mandatory parameter/option.

### remove {#remove}

```javascript
{Collection} remove(child)
```

Deletes an item from a collection.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`child`](#remove-param-child)[*](*star) | — | Type: [collection.Item](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md)

Item to delete. ||
|#

\* Mandatory parameter/option.

### removeAll {#removeAll}

```javascript
{Collection} removeAll()
```

Deletes all the items from a collection.

**Returns** self-reference.

[*star]: Mandatory parameter/option.