Applies an Action Script operation or custom class operation to each element of an array.
|
Syntax |
|
|
|---|---|---|
|
Semantics |
Applies an Action Script 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
Result: JSON
|
|
|
Normalize spaces of each array element Input: an array of article names JSON
Result: JSON
|
||
ActionScript_ArrayOperations_Example
Click here to download a simple example model that shows how to use Action Script to handle arrays with Scheer PAS Designer.
Using “apply” on Complex Arrays
“apply” to a Property of a Complex Array Element
To use apply on properties of complex array elements, 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}
]}
Using “apply” to Build an Array of a Property
You can use apply on an array of complex elements to create an array out of one dedicated property of the array element.
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}
]}
Build a new array using the name property of articles.
set result = apply element.name to articles;
Result:
{ "result": ["AF-1200", "AF-1400", "CD-2002"]}
ActionScript_ArrayOperations_Example
Click here to download a simple example model that shows how to use Action Script to handle arrays with Scheer PAS Designer.
Related Content
Related Pages:
-
reduce Statement
Reduces an array to a scalar value by recursively applying an expression to each array element and its next element. -
select Statement
Selects array items by evaluating a boolean where-expression for each array element and optionally grouping it. -
sort Statement
Sort an array by using an expression to compare array elements with each other.