# 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**](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>&#x3C;<strong>Vector</strong>:from><br>&#x3C;int:start><br>&#x3C;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>&#x3C;<strong>Vector</strong>:from><br>&#x3C;int:start><br>&#x3C;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>&#x3C;int:index1><br>&#x3C;int:index2></p>                                    | _none_      | Exchanges the positions of the two specified elements.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| front           | _none_                                                                           | _variant_   | Returns the first element in the **Vector**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| insert          | <p>&#x3C;int:index><br>&#x3C;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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
