# ModelNodeList

class

Provides an interface to operate on a list of [nodes](module_engine_model_node-ModelNode.md). `NodeList` is used internally in classes like [Element](module_engine_model_element-ModelElement.md) or [ModelDocumentFragment](module_engine_model_documentfragment-ModelDocumentFragment.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L19)

<a id="properties">

## Properties

<a id="member-length">

### `length: number` _(readonly)_

Number of nodes contained inside this node list.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L58)

<a id="member-maxOffset">

### `maxOffset: number` _(readonly)_

Sum of [offset sizes](module_engine_model_node-ModelNode.md#member-offsetSize) of all nodes contained inside this node list.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L65)

<a id="member-_nodes">

### `_nodes: Array<ModelNode>` _(private)_

Nodes contained in this node list.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L23)

<a id="member-_offsetToNode">

### `_offsetToNode: Array<ModelNode>` _(private)_

This array maps numbers (offsets) to node that is placed at that offset.

This array is similar to `_nodes` with the difference that one node may occupy multiple consecutive items in the array.

This array is needed to quickly retrieve a node that is placed at given offset.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L32)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( nodes? )` _(internal)_

Creates a node list.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L40)

#### Parameters

* `nodes?: Iterable<ModelNode>`

  Nodes contained in this node list.

<a id="function-Symbol.iterator">

### `Symbol.iterator() → IterableIterator<ModelNode>`

Iterable interface.

Iterates over all nodes contained inside this node list.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L51)

#### Returns

* `IterableIterator<ModelNode>`

<a id="function-getNode">

### `getNode( index ) → ModelNode | null`

Gets the node at the given index. Returns `null` if incorrect index was passed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L72)

#### Parameters

* `index: number`

#### Returns

* `ModelNode | null`

<a id="function-getNodeAtOffset">

### `getNodeAtOffset( offset ) → ModelNode | null`

Gets the node at the given offset. Returns `null` if incorrect offset was passed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L79)

#### Parameters

* `offset: number`

#### Returns

* `ModelNode | null`

<a id="function-getNodeIndex">

### `getNodeIndex( node ) → number | null`

Returns an index of the given node or `null` if given node does not have a parent.

This is an alias to [`index`](module_engine_model_node-ModelNode.md#member-index).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L88)

#### Parameters

* `node: ModelNode`

#### Returns

* `number | null`

<a id="function-getNodeStartOffset">

### `getNodeStartOffset( node ) → number | null`

Returns the offset at which given node is placed in its parent or `null` if given node does not have a parent.

This is an alias to [`startOffset`](module_engine_model_node-ModelNode.md#member-startOffset).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L97)

#### Parameters

* `node: ModelNode`

#### Returns

* `number | null`

<a id="function-indexToOffset">

### `indexToOffset( index ) → number`

Converts index to offset in node list.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `model-nodelist-index-out-of-bounds` if given index is less than `0` or more than [`length`](#member-length).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L107)

#### Parameters

* `index: number`

#### Returns

* `number`

<a id="function-offsetToIndex">

### `offsetToIndex( offset ) → number`

Converts offset in node list to index.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `model-nodelist-offset-out-of-bounds` if given offset is less than `0` or more than [`maxOffset`](#member-maxOffset).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L132)

#### Parameters

* `offset: number`

#### Returns

* `number`

<a id="function-toJSON">

### `toJSON() → unknown`

Converts `NodeList` instance to an array containing nodes that were inserted in the node list. Nodes are also converted to their plain object representation.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L271)

#### Returns

* `unknown`

  `NodeList` instance converted to `Array`.

<a id="function-_insertNodes">

### `_insertNodes( index, nodes ) → void` _(internal)_

Inserts given nodes at given index.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L166)

#### Parameters

* `index: number`

  Index at which nodes should be inserted.

* `nodes: Iterable<ModelNode>`

  Nodes to be inserted.

#### Returns

* `void`

<a id="function-_removeNodes">

### `_removeNodes( indexStart, howMany ) → Array<ModelNode>` _(internal)_

Removes one or more nodes starting at the given index.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L206)

#### Parameters

* `indexStart: number`

  Index of the first node to remove.

* `howMany: number`

  Number of nodes to remove.

  Defaults to `1`

#### Returns

* `Array<ModelNode>`

  Array containing removed nodes.

<a id="function-_removeNodesArray">

### `_removeNodesArray( nodes ) → void` _(internal)_

Removes children nodes provided as an array. These nodes do not need to be direct siblings.

This method is faster than removing nodes one by one, as it recalculates offsets only once.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/nodelist.ts#L242)

#### Parameters

* `nodes: Array<ModelNode>`

  Array of nodes.

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
