near-runtime-ts > "near" > collections > Vector

A vector class that implements a persistent array.

**T**

**Vector**

constructor

back

first

front

isEmpty

last

length

containsIndex

pop

popBack

push

pushBack

remove

⊕ **new Vector**(prefix: `string`

): Vector

*Defined in* *near.ts:237*

Creates or restores a persistent vector with a given storage prefix. Always use a unique storage prefix for different collections.

**Parameters:**

Name | Type | Description |

prefix |
| A prefix to use for every key of this vector. |

**Returns:** Vector

getback(): `T`

*Defined in* *near.ts:393*

**Returns:** `T`

The last element of the vector. Asserts that the vector is not empty.

getfirst(): `T`

*Defined in* *near.ts:416*

**Returns:** `T`

The first element of the vector. Asserts that the vector is not empty.

getfront(): `T`

*Defined in* *near.ts:408*

**Returns:** `T`

The first element of the vector. Asserts that the vector is not empty.

getisEmpty(): `bool`

*Defined in* *near.ts:278*

**Returns:** `bool`

True if the vector is empty.

getlast(): `T`

*Defined in* *near.ts:401*

**Returns:** `T`

The last element of the vector. Asserts that the vector is not empty.

getlength(): `i32`

*Defined in* *near.ts:285*

**Returns:** `i32`

The length of the vector.

▸ **containsIndex**(index: `i32`

): `bool`

*Defined in* *near.ts:271*

**Parameters:**

Name | Type | Description |

index |
| The index to check. |

**Returns:** `bool`

True if the given index is within the range of the vector indices.

▸ **pop**(): `T`

*Defined in* *near.ts:371*

Removes the last element from the vector and returns it. Asserts that the vector is not empty. Decreases the length of the vector.

**Returns:** `T`

The removed last element of the vector.

▸ **popBack**(): `T`

*Defined in* *near.ts:386*

Removes the last element from the vector and returns it. Asserts that the vector is not empty. Decreases the length of the vector.

**Returns:** `T`

The removed last element of the vector.

▸ **push**(element: `T`

): `i32`

*Defined in* *near.ts:349*

Adds a new element to the end of the vector. Increases the length of the vector.

**Parameters:**

Name | Type | Description |

element |
| A new element to add. |

**Returns:** `i32`

The index of a newly added element

▸ **pushBack**(element: `T`

): `i32`

*Defined in* *near.ts:362*

Adds a new element to the end of the vector. Increases the length of the vector.

**Parameters:**

Name | Type | Description |

element |
| A new element to add. |

**Returns:** `i32`

The index of a newly added element

▸ **remove**(index: `i32`

): `void`

*Defined in* *near.ts:262*

Removes the content of the element from storage without changing length of the vector.

**Parameters:**

Name | Type | Description |

index |
| The index of the element to remove. |

**Returns:** `void`