---
title: "ArrayModel"
---
Defined in: [api/node/typescript/models.ts:238](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L238)

ArrayModel wraps a JavaScript array for use in `.slint` views. The underlying
array can be modified with the [[ArrayModel.push]], [[ArrayModel.remove]], and
[[ArrayModel.splice]] methods.

## Extends

- [`Model`](/latest/docs/node/api/classes/model/)\<`T`\>

## Type Parameters

### T

`T`

## Constructors

### Constructor

> **new ArrayModel**\<`T`\>(`arr`): `ArrayModel`\<`T`\>

Defined in: [api/node/typescript/models.ts:249](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L249)

Creates a new ArrayModel.

#### Parameters

##### arr

`T`[]

#### Returns

`ArrayModel`\<`T`\>

#### Overrides

`Model<T>.constructor`

## Accessors

### length

#### Get Signature

> **get** **length**(): `number`

Defined in: [api/node/typescript/models.ts:257](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L257)

Returns the number of entries in the array model.

##### Returns

`number`

## Methods

### \[iterator\]()

> **\[iterator\]**(): `Iterator`\<`T`\>

Defined in: [api/node/typescript/models.ts:195](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L195)

#### Returns

`Iterator`\<`T`\>

#### Inherited from

[`Model`](/latest/docs/node/api/classes/model/).[`[iterator]`](/latest/docs/node/api/classes/model/#iterator)

***

### entries()

> **entries**(): `IterableIterator`\<\[`number`, `T`\]\>

Defined in: [api/node/typescript/models.ts:386](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L386)

Returns an iterable of key, value pairs for every entry in the array.

#### Returns

`IterableIterator`\<\[`number`, `T`\]\>

***

### filter()

> **filter**(`filterFunction`): [`FilterModel`](/latest/docs/node/api/classes/filtermodel/)\<`T`\>

Defined in: [api/node/typescript/models.ts:118](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L118)

Returns a new Model that only contains the rows of this model for which
`filterFunction` returns true.

#### Parameters

##### filterFunction

(`data`) => `boolean`

returns true if a row should be visible.

#### Returns

[`FilterModel`](/latest/docs/node/api/classes/filtermodel/)\<`T`\>

a new [FilterModel](/latest/docs/node/api/classes/filtermodel/) that wraps the current model.

#### Inherited from

[`Model`](/latest/docs/node/api/classes/model/).[`filter`](/latest/docs/node/api/classes/model/#filter)

***

### insertRow()

> **insertRow**(`index`, `data`): `void`

Defined in: [api/node/typescript/models.ts:305](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L305)

Insert a new row into the array backing the model at the specified index and notifies run-time about the added row.
Throws a RangeError when the index is out of bounds.

#### Parameters

##### index

`number`

index at which to insert the new row.

##### data

`T`

data item to store in the new row.

#### Returns

`void`

#### Overrides

[`Model`](/latest/docs/node/api/classes/model/).[`insertRow`](/latest/docs/node/api/classes/model/#insertrow)

***

### map()

> **map**\<`U`\>(`mapFunction`): [`MapModel`](/latest/docs/node/api/classes/mapmodel/)\<`T`, `U`\>

Defined in: [api/node/typescript/models.ts:108](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L108)

Returns a new Model where all elements are mapped by the function `mapFunction`.

#### Type Parameters

##### U

`U`

#### Parameters

##### mapFunction

(`data`) => `U`

maps the data from T to U.

#### Returns

[`MapModel`](/latest/docs/node/api/classes/mapmodel/)\<`T`, `U`\>

a new [MapModel](/latest/docs/node/api/classes/mapmodel/) that wraps the current model.

#### Inherited from

[`Model`](/latest/docs/node/api/classes/model/).[`map`](/latest/docs/node/api/classes/model/#map)

***

### pop()

> **pop**(): `T` \| `undefined`

Defined in: [api/node/typescript/models.ts:328](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L328)

Removes the last element from the array and returns it.

#### Returns

`T` \| `undefined`

The removed element or undefined if the array is empty.

***

### push()

> **push**(...`values`): `void`

Defined in: [api/node/typescript/models.ts:317](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L317)

Pushes new values to the array that's backing the model and notifies
the run-time about the added rows.

#### Parameters

##### values

...`T`[]

list of values that will be pushed to the array.

#### Returns

`void`

***

### pushRow()

> **pushRow**(`data`): `void`

Defined in: [api/node/typescript/models.ts:169](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L169)

Adds a line to the model with the provided data.
Throws when the model rejects the modification.
The default implementation calls [Model.insertRow](/latest/docs/node/api/classes/model/#insertrow) with the row count.

#### Parameters

##### data

`T`

new data item to store in a new row.

#### Returns

`void`

#### Inherited from

[`Model`](/latest/docs/node/api/classes/model/).[`pushRow`](/latest/docs/node/api/classes/model/#pushrow)

***

### remove()

> **remove**(`index`, `size`): `void`

Defined in: [api/node/typescript/models.ts:342](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L342)

Removes the specified number of element from the array that's backing
the model, starting at the specified index.

#### Parameters

##### index

`number`

index of first row to remove.

##### size

`number`

number of rows to remove.

#### Returns

`void`

***

### removeRow()

> **removeRow**(`index`): `void`

Defined in: [api/node/typescript/models.ts:292](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L292)

Remove a row from the array backing the model and notifies run-time about the removed row.
Throws a RangeError when the index is out of bounds.

#### Parameters

##### index

`number`

index of the row to remove.

#### Returns

`void`

#### Overrides

[`Model`](/latest/docs/node/api/classes/model/).[`removeRow`](/latest/docs/node/api/classes/model/#removerow)

***

### reverse()

> **reverse**(): [`ReverseModel`](/latest/docs/node/api/classes/reversemodel/)\<`T`\>

Defined in: [api/node/typescript/models.ts:137](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L137)

Returns a new Model with the same rows as this model, in reverse order.

#### Returns

[`ReverseModel`](/latest/docs/node/api/classes/reversemodel/)\<`T`\>

a new [ReverseModel](/latest/docs/node/api/classes/reversemodel/) that wraps the current model.

#### Inherited from

[`Model`](/latest/docs/node/api/classes/model/).[`reverse`](/latest/docs/node/api/classes/model/#reverse)

***

### rowCount()

> **rowCount**(): `number`

Defined in: [api/node/typescript/models.ts:264](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L264)

Returns the number of entries in the array model.

#### Returns

`number`

#### Overrides

[`Model`](/latest/docs/node/api/classes/model/).[`rowCount`](/latest/docs/node/api/classes/model/#rowcount)

***

### rowData()

> **rowData**(`row`): `T`

Defined in: [api/node/typescript/models.ts:273](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L273)

Returns the data at the specified row.

#### Parameters

##### row

`number`

index in range 0..(rowCount() - 1).

#### Returns

`T`

undefined if row is out of range otherwise the data.

#### Overrides

[`Model`](/latest/docs/node/api/classes/model/).[`rowData`](/latest/docs/node/api/classes/model/#rowdata)

***

### setRowData()

> **setRowData**(`row`, `data`): `void`

Defined in: [api/node/typescript/models.ts:282](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L282)

Stores the given data on the given row index and notifies run-time about the changed row.

#### Parameters

##### row

`number`

index in range 0..(rowCount() - 1).

##### data

`T`

new data item to store on the given row index

#### Returns

`void`

#### Overrides

[`Model`](/latest/docs/node/api/classes/model/).[`setRowData`](/latest/docs/node/api/classes/model/#setrowdata)

***

### sort()

> **sort**(`compareFunction`): [`SortModel`](/latest/docs/node/api/classes/sortmodel/)\<`T`\>

Defined in: [api/node/typescript/models.ts:129](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L129)

Returns a new Model with the same rows as this model, ordered according to
`compareFunction`.

#### Parameters

##### compareFunction

(`a`, `b`) => `number`

compares two rows the same way the callback passed to
                        Array.prototype.sort does.

#### Returns

[`SortModel`](/latest/docs/node/api/classes/sortmodel/)\<`T`\>

a new [SortModel](/latest/docs/node/api/classes/sortmodel/) that wraps the current model.

#### Inherited from

[`Model`](/latest/docs/node/api/classes/model/).[`sort`](/latest/docs/node/api/classes/model/#sort)

***

### splice()

> **splice**(`start`, `deleteCount?`, ...`items`): `T`[]

Defined in: [api/node/typescript/models.ts:357](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L357)

Removes elements from the array that's backing the model and, if
necessary, inserts new elements in their place, following the semantics
of `Array.prototype.splice`. The run-time is notified about the removed
and added rows.

#### Parameters

##### start

`number`

zero-based index at which to start changing the array; negative values count back from the end and out-of-range values are clamped.

##### deleteCount?

`number`

number of elements to remove starting at `start`; if omitted, all elements from `start` to the end are removed.

##### items

...`T`[]

elements to insert at `start`.

#### Returns

`T`[]

an array containing the removed elements.

***

### values()

> **values**(): `IterableIterator`\<`T`\>

Defined in: [api/node/typescript/models.ts:379](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L379)

Returns an iterable of values in the array.

#### Returns

`IterableIterator`\<`T`\>