apply Statement
Applies an Action Script operation or custom class operation to each element of an array.
Syntax |
| |
---|---|---|
Semantics | Applies an Action Acript operation or class operation ( The array elements can be of simple or complex type. | |
Substitutables |
| Can be any action script operation or custom class operation. The operation must return an object of the array type. |
| Can be any variable or object attribute having the type Array. | |
Examples | Concatenate a string to each array element Input: an array of article names
JSON
CODE
Result:
JSON
| |
Normalize spaces of each array element Input: an array of article names
JSON
CODE
Result:
JSON
|
Use apply on Complex Arrays
To use apply on arrays containing complex objects, you need to implement a custom operation that returns a changed object. The example below shows how to perform a calculation on the price property of a complex article object.
Input: an array of a complex article objects
{ "articles": [
{"name": "AF-1200", "price": 64.50},
{"name": "AF-1400", "price": 72.50},
{"name": "CD-2002", "price": 570.00}
]}
set result = apply element.raisePrice(1.1) to articles;
raisePrice() in this example is a custom operation that takes an article object, does the calculations, and returns a modified article object.
Result:
{ "articles": [
{"name": "AF-1200", "price": 70.95},
{"name": "AF-1400", "price": 79.75},
{"name": "CD-2002", "price": 627.00}
]}
Related Pages: