# Vector

The **Vector** object is provided to address some short-comings in ActiveX scripting's array support. Some languages have better support than others for arrays, but the languages aren't consistent and some (like *JScript*) have incompatible arrays that Opus is unable to access at all. Therefore, any Opus scripting objects that take or return an array-like variable will use (or prefer to use) a **Vector** rather than an array.

A **Vector** object is mostly able to be used as a straight drop-in replacement for an arrays. They are *collections* and so can be enumerated, or accessed via index (e.g. **Vector(4)** to access the fifth element).  They also have a number of helper methods to make manipulating them easier than arrays often are.

Note that in *JScript* you can access an element using square brackets (just like an array) or parentheses (as if it was a function parameter). In other languages, like *VBScript*, you can only use parentheses.

You can create a new **Vector** using the [**DOpusFactory**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/dopusfactory)**.Vector** method.

| Property Name | Return Type | Description                                                                                                                                                                                                                                  |
| ------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| capacity      | *int*       | Returns the capacity of the **Vector** (the number of elements it can hold without having to reallocate memory). This is not the same as the number of elements it currently holds, which can be 0 even if the capacity is something larger. |
| count         | *int*       | Returns the number of elements the **Vector** currently holds.                                                                                                                                                                               |
| empty         | *bool*      | Returns **True** if the **Vector** is empty, **False** if not.                                                                                                                                                                               |
| length        | *int*       | A synonym for **count**.                                                                                                                                                                                                                     |
| size          | *int*       | A synonym for **count**.                                                                                                                                                                                                                     |

| Method Name     | **Arguments**                                                       | Return Type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| --------------- | ------------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| append          | <p><<strong>Vector</strong>:from><br>\<int:start><br>\<int:end></p> | *none*      | <p>Copies the values of another <strong>Vector</strong> to the end of this one, preserving the existing values as well. If <em>start</em> and <em>end</em> are not provided, the entire <strong>Vector</strong> is appended - otherwise, only the specified elements are appended.</p><p>Instead of a <strong>Vector</strong> object you can also pass a <em>collection</em> to this method and the contents of the collection will be copied to the end of the <strong>Vector</strong>.<br>In <em>JScript</em> you can pass a standard array to this method to copy the array to the end of a <strong>Vector</strong>.</p> |
| assign          | <p><<strong>Vector</strong>:from><br>\<int:start><br>\<int:end></p> | *none*      | <p>Copies the value of another <strong>Vector</strong> to this one. If <em>start</em> and <em>end</em> are not provided, the entire <strong>Vector</strong> is copied - otherwise, only the specified elements are copied.</p><p>Instead of a <strong>Vector</strong> object you can also pass a <em>collection</em> to this method and the contents of the collection will be copied to the <strong>Vector</strong>.</p><p>In <em>JScript</em> you can pass a standard array to this method to copy the array into a <strong>Vector</strong>.</p>                                                                          |
| back            | *none*                                                              | *variant*   | Returns the last element in the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| clear           | *none*                                                              | *none*      | Clears the contents of the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| erase           | \<int:index>                                                        | *none*      | Erases the element at the specified index.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| exchange        | <p>\<int:index1><br>\<int:index2></p>                               | *none*      | Exchanges the positions of the two specified elements.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| front           | *none*                                                              | *variant*   | Returns the first element in the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| insert          | <p>\<int:index><br>\<variant:value></p>                             | *none*      | Inserts the provided value at the specified position.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| pop\_back       | *none*                                                              | *none*      | Removes the last element of the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| push\_back      | \<variant:value>                                                    | *none*      | Adds the provided value to the end of the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| reserve         | \<int:capacity>                                                     | *none*      | <p>Reserves space in the <strong>Vector</strong> for the specified number of elements (increases its <strong>capacity</strong>, although the <strong>count</strong> of elements remains unchanged).</p><p>Note that <strong>Vectors</strong> grow dynamically - you don't have to specifically reserve or resize them. However if you want to add a large number of elements to a <strong>Vector</strong> it can be more efficient to reserve space for them first.</p>                                                                                                                                                     |
| resize          | \<int:size>                                                         | *none*      | Resizes the **Vector** to the specified number of elements. Any existing elements past the new size of the **Vector** will be erased.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| reverse         | *none*                                                              | *none*      | Reverses the order of the elements held by the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| shrink\_to\_fit | *none*                                                              | *none*      | Reduces the capacity of the **Vector** to the number of elements it currently holds.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| sort            | *none*                                                              | *none*      | Sorts the contents of the **Vector**. Strings and numbers are sorted alphabetically and numerically - other elements are grouped by type but not specifically sorted in any particular order.                                                                                                                                                                                                                                                                                                                                                                                                                               |
| unique          | *none*                                                              | *int*       | Removes all but one of any duplicate elements from the **Vector**. The number of elements removed is returned.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/vector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
