Returns the value that the array contains in the indicated position.
1 array.get
<array.get name='name'>
<array /> ?
<row /> !
</array.get>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the variable of array type. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Earray | array | The array object can be referenced by name using the name attribute or it can be passed as an argument to the function. | |||
Erow | integer | Position of the object in the array. The first index is 0 and the last one is length -1 (array.size - 1). |
Returns | |
---|---|
Type | Description |
Object | Returns the passed object as an argument converted to an array. |
Example
Get the first element of an array using a number as an index.
Copy
<xsql-script name='array_get_test1'> <body> <array name='cities'> <string>Barcelona</string> <string>Paris</string> <string>Roma</string> </array> <println> <array.get name='cities'> <number>0</number> </array.get> </println> </body> </xsql-script>
Reference is made to the first element of the collection, the string 'Barcelona', with the integer 0.
The result is:
Copy
Barcelona
Example
Get the third element of an array using a variable as an index.
Copy
<xsql-script name='array_get_test2'> <body> <array name='cities'> <string>Barcelona</string> <string>Paris</string> <string>Roma</string> </array> <set name='position'>2</set> <println> <array.get name='cities'> <position/> </array.get> </println> </body> </xsql-script>
The index is contained into the variable position, which is declared and assigned previously.
The result is:
Copy
Roma