Iterates over every element of a List object and can call a UDF function, passed as the second argument.
listEach(String str, UDFMethod function [, String delim, boolean includeEmptyFields]);
returns void
Name | Type | Required | Default | Description |
---|---|---|---|---|
str | string | Yes | An input list object. | |
function | function | Yes | UDF or closure object. | |
delim | string | Yes | A list delimiter to be used. The default value is comma (,). | |
includeEmptyFields | boolean | No | false | Boolean. Whether to allow empty fields. Default is false. |
Using a semicolon delimiter.
list = "a;b;c";
listEach(list, function(element,index,list) {
writeOutput("#index#:#element#;");
}, ";");
List Loop list.listEach()
list = "a;b;c";
list.listEach(function(element,index,list) {
writeOutput("#index#:#element#;");
}, ";");
Example 1
empArray = ["john", "pete", "bob"];
listS = "'john', 'pete', 'bob'";
arrayEach(empArray, xclosure);
listEach(listS, xclosure);
function xclosure(empname, index) {
writeOutput(empName & " at index: " & index);
}
Example 2
cityList = "Pittsburgh, Raleigh, Miami, Las Vegas";
function printCity(String city) {
writeOutput("Current city: " & city);
}
listEach(cityList ,printCity);