Add a specific element at the end of a variable type array.
1 array.add
<array.add name='name'>
<value /> +
</array.add>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the variable of array type. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | object | Object to add to the specified array. |
Returns | |
---|---|
Type | Description |
Object[] | Returns the array of the objects that have been added. |
Example
Add an element contained in a variable to an array.
Copy
<xsql-script name='array_add_test1'> <body> <array name='cities'> <string>Barcelona</string> <string>Paris</string> <string>Roma</string> </array> <array.add name='cities'> <string>Viena</string> <string>San Sebastian</string> </array.add> <println><cities/></println> </body> </xsql-script>
Two new elements are added to ‘Cities’ variable: ‘Viena’ and ‘San Sebastián’.
The result is:
Copy
Barcelona Paris Roma Viena San Sebastian
Example
Add an element contained in a variable to an array.
Copy
<xsql-script name='array_add_test2'> <body> <array name='cities'> <string>Barcelona</string> <string>Paris</string> <string>Roma</string> </array> <set name='city'>Londres</set> <array.add name='ciudades'><city/></array.add> <println><cities/></println> </body> </xsql-script>
It is declared a variable named city to which the value 'London' is assigned, which in the following line is also added to the collection of cities. The structure therefore has 3 to 4 elements.
The result is:
Copy
Barcelona Paris Roma Londres