Returns the element that contains the array in the indicated position.
1 array.getElementAt
<array.getElementAt
name='name'
position='position'
>
<array /> ?
</array.getElementAt>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the variable of array type. | |||
Aposition | integer | Position of the element to be returned within the array. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Earray | array | The array object can be referenced by name using the attribute name or it can be passed as an argument of the function. |
Returns | |
---|---|
Type | Description |
Object | Returns the element that contains the array in the indicated position. |
Example
Get the first element of an array using a number as un index. In this example, the array will be referred to as an attribute.
Copy
<xsql-script name='array_getElementAt_test1'> <body> <array name='cities'> <string>Barcelona</string> <string>Paris</string> <string>Roma</string> </array> <println><array.getElementAt name='cities' position='0' /></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 second element of the array using a variable as an index.
Copy
<xsql-script name='array_getElementAt_test2'> <body> <array name='cities'> <string>Barcelona</string> <string>Paris</string> <string>Roma</string> </array> <println> <array.getElementAt position='1'> <cities/> </array.getElementAt> </println> </body> </xsql-script>
In this case, the array will be called as an argument.
The result is:
Copy
Paris