Keyword

# Array

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Assigns a list of values to consecutive elements of a one-dimensional <span class="title-ref">Array</span>.

## Usage

``` xojo
result = Array(elementList)
```

| Part        | Type                                                           | Description                                                                                         |
|-------------|----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| result      | Any valid datatype for an <span class="title-ref">array</span> | Name of the <span class="title-ref">array</span> that is populated with the items in *elementList*. |
| ElementList | Type of *result*                                               | A comma-delimited list of values that are used to populate *result*.                                |

## Notes

<div class="note">

<div class="title">

Note

</div>

Only one-dimensional arrays are supported by <span class="title-ref">Array</span>. Higher dimensional arrays can be populated via assignment statements.

</div>

The <span class="title-ref">Array</span> function provides the same functionality as separate assignment statements for each element of an <span class="title-ref">Array</span>, beginning with element zero and proceeding consecutively. If there are more elements in the <span class="title-ref">Array</span> than items in the list of elements, then the "extra" elements are not disturbed.

All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Type considerations

If the *ElementList* contains numeric data of different word lengths and/or a mixture of signed and unsigned integers, <span class="title-ref">Array</span> will use the lowest common data type that accommodates all the elements.

For example, because hexadecimal numbers are unsigned integers, the following code will generate a `Type Mismatch</api/errors>` Error:

``` xojo
Var hexNums() As Integer
hexNums = Array(&h1, &h2)
```

You need to be careful about word length and whether or not the integer is signed. You should instead declare the <span class="title-ref">Array</span> of type UInt64:

``` xojo
Var bigInts() As UInt64
bigInts = Array(&h1, &h2)
```

If you wish, you can also decide to convert one of the values to a signed integer. In that case, <span class="title-ref">Array</span> will return an `Integer</api/data_types/integer>` <span class="title-ref">Array</span>. Use either of the following ways:

``` xojo
Var numbers() As Integer
numbers = Array(Int64(&h1), &h2) ' Once you convert one value type, the rest will follow
```

Or this:

``` xojo
Var numbers() As Integer
numbers = Array(1, &h2)
```

## Sample code

The following statements initialize the <span class="title-ref">Array</span> using separate assignment statements for each <span class="title-ref">Array</span> element:

``` xojo
Var names(2) As String
//using separate assignment statements
names(0) = "Fred"
names(1) = "Ginger"
names(2) = "Stanley"
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following statements use the <span class="title-ref">Array</span> function to accomplish the same thing. Note that you don't have to declare the exact size of the <span class="title-ref">Array</span> in the `Var</api/language/var>` statement. The <span class="title-ref">Array</span> function will add elements to the <span class="title-ref">Array</span> as needed.

The following statement creates and populates the first three elements of the <span class="title-ref">Array</span> *aNames*.

``` xojo
Var names() As String
' using the Array function
names = Array("Fred", "Ginger", "Stanley")
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Arrays</api/language/arrays>` concept; `Var</api/language/var>`, `For Each...Next</api/language/loops/for_each...next>`, `ParamArray</api/language/paramarray>` commands; `Dictionary</api/language/dictionary>` class; `Collections of Data</getting_started/using_the_xojo_language/collections_of_data>` topic

</div>
