Description
Iterates over every entry of the struct and calls the closure to work on the key value pair of the struct. This function will reduce the struct to a single value and will return the value.
Returns
any
Syntax
StructReduce(struct, function(result, key, value [,struct]), initialVal) |
History
ColdFusion 11: Added this function.
Attributes
Attribute |
Req/Opt |
Default |
Description |
---|---|---|---|
struct | Required | The input struct. | |
function | Required | Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are
|
|
initialVal | Optional | Initial value which will be used for the reduce operation. The type is any. |
Example
<cfscript> person = {fname="John", lname="Doe"}; ucaseStruct = structMap(person, function(key, value) { return ucase(value); }); writeDump(ucaseStruct); concatValues = structReduce(person, function(result, key, value) { result = result?:""; result&= value & " "; return result; }); writeDump(concatValues); </cfscript> |