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

# objectManager.ObjectCollection

Extends [ICollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICollection.md), [ICustomizable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md).

Collection of objects added to the layer.

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

## Constructor {#constructor-summary}

```javascript
objectManager.ObjectCollection()
```

## Fields {#properties-summary}

#|
|| **Name** | **Type** | **Description** ||
|| [balloon](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#balloon) | [objectManager.Balloon](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.Balloon.md) | Object balloon in the manager. ||
|| [events](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events) | [IEventManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventManager.md) | Event manager.

Inherited from [IEventEmitter](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events). ||
|| [hint](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#hint) | [objectManager.Hint](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.Hint.md) | Object hint in the [ObjectManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md). ||
|| [options](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#options) | [option.Manager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/option.Manager.md) | Options manager. Names of fields that are available via the option.Manager#get method: 
- hasBalloon - Indicates whether the collection has the .balloon field. If a balloon doesn't need to be opened when clicking the object, we recommend setting this option to the "false" value to avoid unnecessary initializations.
- hasHint - Indicates whether the collection has the .hint field. If a popup hint doesn't need to be displayed when the object is pointed at, we recommend setting this option to the "false" value to avoid unnecessary initializations.
- hideIconOnBalloonOpen - Hide the icon when opening the balloon. Default value: true.
- openBalloonOnClick - Show the balloon when clicking the object. Default value: true. ||
|| [overlays](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#overlays) | [objectManager.OverlayCollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.OverlayCollection.md) | Collection of overlays of singular objects. All events, with the exception of "add" and "remove" events, propagate from the collection of overlays to the collection of objects. ||
|#

## Events {#events-summary}

#|
|| **Name** | **Description** ||
|| [add](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#event-add) | Adds an object to the collection. Instance of the [Event](https://yandex.com.tr/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.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- objectId - ID of the added object.
- child - The added object. ||
|| [objectoptionschange](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#event-objectoptionschange) | Modification of object options via the [objectManager.ObjectCollection.setObjectOptions](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#setObjectOptions) method. Instance of the [Event](https://yandex.com.tr/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.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- objectId - ID of the object that had options modified. ||
|| [optionschange](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange) | Change to the object options.

Inherited from [ICustomizable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange). ||
|| [remove](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#event-remove) | Removes an object from the collection. Instance of the [Event](https://yandex.com.tr/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.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- objectId - ID of the deleted object.
- child - The deleted object. ||
|#

## Methods {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [add](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#add)([data](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#add-param-data)) | [objectManager.ObjectCollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md) | This method completely duplicates the logic of [ObjectManager.add](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md#add). ||
|| [each](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#each)([callback](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#each-param-callback), [context](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#each-param-context)) | | A method that calls the passed handler function for all the items in the collection. ||
|| [getAll](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#getAll)() | Object[] | Returns array of objects contained in the collection. ||
|| [getById](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#getById)([id](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#getById-param-id)) | Object\|null | Returns the object, or null if an object with the passed ID does not exist. ||
|| [getIterator](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICollection.md#getIterator)() | [IIterator](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IIterator.md) | Returns iterator for the collection.

Inherited from [ICollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICollection.md#getIterator). ||
|| [getLength](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#getLength)() | Number | Returns the number of objects in the collection. ||
|| [getObjectManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#getObjectManager)() | [ObjectManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md) | Returns the parent layer of objects in the collection. ||
|| [remove](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#remove)([data](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#remove-param-data)) | [objectManager.ObjectCollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md) | This method completely duplicates the logic of [ObjectManager.remove](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md#remove). ||
|| [removeAll](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#removeAll)() | [objectManager.ObjectCollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md) | Deletes all the items from a collection. ||
|| [setObjectOptions](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#setObjectOptions)([objectId](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#setObjectOptions-param-objectId), [options](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#setObjectOptions-param-options)) | [objectManager.ObjectCollection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md) | A method that allows to dynamically update object options. This method should be used when you want new options to be immediately applied to the object representation on the map. Note that the manager ignores the 'visible' option. ||
|#

## Fields details {#field_detail}

### balloon {#balloon}

```javascript
{objectManager.Balloon} balloon
```

Object balloon in the manager.

### hint {#hint}

```javascript
{objectManager.Hint} hint
```

Object hint in the [ObjectManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md).

### options {#options}

```javascript
{option.Manager} options
```

Options manager. Names of fields that are available via the option.Manager#get method: 
- hasBalloon - Indicates whether the collection has the .balloon field. If a balloon doesn't need to be opened when clicking the object, we recommend setting this option to the "false" value to avoid unnecessary initializations.
- hasHint - Indicates whether the collection has the .hint field. If a popup hint doesn't need to be displayed when the object is pointed at, we recommend setting this option to the "false" value to avoid unnecessary initializations.
- hideIconOnBalloonOpen - Hide the icon when opening the balloon. Default value: true.
- openBalloonOnClick - Show the balloon when clicking the object. Default value: true.

**Example:**

```javascript
// Creating styles for individual objects within the collection.
objectManager.objects.options.set({
    preset: 'islands#redIcon',
    hasBalloon: false,
    zIndex: 500
});
```

### overlays {#overlays}

```javascript
{objectManager.OverlayCollection} overlays
```

Collection of overlays of singular objects. All events, with the exception of "add" and "remove" events, propagate from the collection of overlays to the collection of objects.

**Example:**

```javascript
objectManager.objects.overlays.events.add('add', function (e) {
    alert('The object ' + e.get('objectId') + ' is shown on the map.');
});
```

## Events details {#event_detail}

### add {#add}

Adds an object to the collection. Instance of the [Event](https://yandex.com.tr/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.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- objectId - ID of the added object.
- child - The added object.

### objectoptionschange {#objectoptionschange}

Modification of object options via the [objectManager.ObjectCollection.setObjectOptions](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/objectManager.ObjectCollection.md#setObjectOptions) method. Instance of the [Event](https://yandex.com.tr/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.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- objectId - ID of the object that had options modified.

### remove {#remove}

Removes an object from the collection. Instance of the [Event](https://yandex.com.tr/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.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- objectId - ID of the deleted object.
- child - The deleted object.

## Methods details {#method_detail}

### add {#add}

```javascript
{objectManager.ObjectCollection} add(data)
```

This method completely duplicates the logic of [ObjectManager.add](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md#add).

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`data`](#add-param-data)[*](*star) | — | Type: Object|Object[]\|String

Objects to add to the layer. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
objectManager.objects.add({
    type: 'Feature',
    geometry: {
        type: 'Point',
        coordinates: [55.33, 36.64]
    }
});
```

### each {#each}

```javascript
{} each(callback, context)
```

A method that calls the passed handler function for all the items in the collection.

**Parameters:**

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

Handler function that the collection objects are passed to. ||
|| [`context`](#each-param-context)[*](*star) | — | Type: Object

Context for the handler function. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
var singleCounter = 0;
var clusterCounter = 0;
objectManager.objects.each(function (object) {
    var objectState = objectManager.getObjectState(object.id);
    if (objectState.isClustered) {
        clusterCounter++;
    } else {
        if (objectState.isShown) {
            singleCounter++;
        }
    }
});
alert('Number of single placemarks shown: ' + singleCounter);
alert('Number of placemarks shown in clusters: ' + clusterCounter);
```

### getAll {#getAll}

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

**Returns** array of objects contained in the collection.

### getById {#getById}

```javascript
{Object|null} getById(id)
```

**Returns** the object, or null if an object with the passed ID does not exist.

**Parameters:**

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

Object ID. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
objectManager.objects.add('click', function (e) {
    var objectId = e.get('objectId');
    var object = objectManager.objects.getById(objectId);
});
```

### getLength {#getLength}

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

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

**Example:**

```javascript
alert('Number of objects in the layer: ' + objectManager.objects.getLength());
```

### getObjectManager {#getObjectManager}

```javascript
{ObjectManager} getObjectManager()
```

**Returns** the parent layer of objects in the collection.

### remove {#remove}

```javascript
{objectManager.ObjectCollection} remove(data)
```

This method completely duplicates the logic of [ObjectManager.remove](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ObjectManager.md#remove).

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`data`](#remove-param-data)[*](*star) | — | Type: Object|Object[]\|String

The objects to delete. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
// Removing the objects with the IDs 34 and 25.
objectManager.objects.remove([34, 25]);
```

### removeAll {#removeAll}

```javascript
{objectManager.ObjectCollection} removeAll()
```

Deletes all the items from a collection.

**Returns** self-reference.

**Example:**

```javascript
objectManager.objects.removeAll();
```

### setObjectOptions {#setObjectOptions}

```javascript
{objectManager.ObjectCollection} setObjectOptions(objectId, options)
```

A method that allows to dynamically update object options. This method should be used when you want new options to be immediately applied to the object representation on the map. Note that the manager ignores the 'visible' option.

**Returns** self-reference.

**Parameters:**

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

ID of the object to set options for. ||
|| [`options`](#setObjectOptions-param-options)[*](*star) | — | Type: Object

New object options. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
// Changing the icon color when moused over.
objectManager.objects.events.add('mouseenter', function (e) {
    var objectId = e.get('objectId');
    var overlay = objectManager.objects.overlays.getById(objectId);
    setRedColor(objectId);
    overlay.events.add('mapchange', setGreenColor);
});

objectManager.objects.events.add('mouseleave', function (e) {
    var objectId = e.get('objectId');
    var overlay = objectManager.objects.overlays.getById(objectId);
    setGreenColor(objectId);
    overlay.events.remove('mapchange', setGreenColor);
});

function setGreenColor (objectId) {
    objectManager.objects.setObjectOptions(objectId, {
        preset: 'islands#greenIcon'
    });
}

function setRedColor (objectId) {
    objectManager.objects.setClusterOptions(objectId, {
        preset: 'islands#redIcon'
    });
}
```

[*star]: Mandatory parameter/option.