StringReduce()
Iterates over every element of the string and calls the closure to work on the elements of the string. This function will reduce the string to a single value and will return the value.
Introduced: 6.0.0.105
StringReduce( string=string, closure=function, initialVal=any );
Returns: any
| Argument | Description |
|---|---|
|
string
string,
required
|
edit
Input string. Alias: inputString, object |
|
closure
function,
required
|
edit
Closure or a function reference that will be called for each of the iteration. Alias: function, callback, udf |
|
initialVal
any,
optional
|
edit
Initial value that will be used for the reduce operation. Alias: initial, initalValue |
Usage Notes
editSince Lucee 6, this function iterates over each character in the string.
For list-based iteration with delimiters, use ListReduce() instead.
Examples
editletters="abcdef";
closure=function(value1,value2){return value1 & value2;}
writeOutput( stringReduce(letters,closure,"z") );
See also
- string.reduce()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)