Whatever message this page gives is out now! Go check it out!

StringReduce

Last update:
May 18, 2026

Description

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.

Returns

Any

Category

Syntax

StringReduce(String string, UDFMethod callback, Object initialValue)

History

ColdFusion (2021 release): Added in this release.

Parameters

Parameter
Description
string
(Required) The input string
callback
(Required) Closure or a function reference that will be called for each of the iteration.
initialVal
(Optional) Initial value that will be used for the reduce operation. The type is any.

Example

<cfscript> 
    myStr="2021"; 
    closure=function(value1,value2){      
        return (value1 & value2);  
    } 
    writeOutput(StringReduce(myStr,closure,"ColdFusion")) 
    //writeOutput(myStr.reduce(closure,"ColdFusion")) 
</cfscript>
Output
ColdFusion2021
EXAMPLE 2
<cfscript> 
    closure=function(value1,value2){               
        return (value1&value2);  
      } 
      writeOutput(StringReduce(callback=closure,initialValue="Hello",string="World")) 
</cfscript>
Output
HelloWorld

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page