Skip to main content
Skip table of contents

apply Statement

Applies an Action Script operation or custom class operation to each element of an array.

Syntax

apply operationName(element [, additionalParameter]) to targetArrayName
apply element.operationName([parameter]) to targetArrayName

Semantics

Applies an Action Script operation or class operation (operationName) to each element of an array (targetArrayName).

apply changes the target array.

The array elements can be of simple or complex type. element is a keyword and denotes any single element of the target array (targetArrayName).

Substitutables

operationName

Can be any action script operation or custom class operation. The operation must return an object of the array type.

targetArrayName

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
{"articles": ["AF-1200", "AF-1400", "CD-2002", "RC-0001"]}
CODE
set result = apply concat(element, "_new") to articles;

Result:

JSON
{"result": ["AF-1200_new", "AF-1400_new", "CD-2002_new", "RC-0001_new"]}

Normalize spaces of each array element

Input: an array of article names

JSON
{"articles": ["  AF-1200", "AF-1400  ", "  CD-2002  ", "RC   0001", "K-6"]}
CODE
set result = apply normalizeSpaces(element) to articles;

Result:

JSON
{"result": ["AF-1200", "AF-1400", "CD-2002", "RC 0001", "K-6"]}

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

JSON
{ "articles": [
    {"name": "AF-1200", "price": 64.50},
    {"name": "AF-1400", "price": 72.50},
    {"name": "CD-2002", "price": 570.00}
]}
CODE
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:

JSON
{ "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

JSON
{ "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.

CODE
set result = apply element.name to articles;

Result:

JSON
{ "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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.