Whatever message this page gives is out now! Go check it out!
structEach(struct,function(key, value [, struct]){} [, parallel] [, maxThreadCount])Parameter | Description |
struct | Name of the structure object. |
function | Inline function executed for each key - value pair in the struct. |
key | Key in a struct. |
value | Value in a struct. |
parallel | (Boolean)- True if you want to enable parallel programming. |
maxThreadCount | (Int) The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
<cfscript>
myStruct=StructNew();
myStruct = {a:1,b=2,c=3,d=4,e=5}; // Define key-value pairs
// Run StructEach with an inline function
StructEach(myStruct,function(key,value) {
WriteOutput('The value of ' & key & ' is ' & value & '; ');
});
</cfscript><cfscript>
myStruct=StructNew();
myStruct = {team:"Chicago Bulls",player:"Michael Jordan", sport:"basketball"}; // Define key-value pairs
// Create a named function that takes two arguments as key and value
function getValues(key, value) {
writeOutput('My favorite ' & key & ' is ' & value & " | ");
}
// Run StructEach with the named function getValues
structEach(myStruct,getValues);
</cfscript><cfscript>
myStruct = {a:1,b=2,c=3,d=4,e=5}; // Define key-value pairs
myStruct.each(function(key,value){
WriteOutput("#key#:#value#");
});
</cfscript><cfscript>
mystruct= Structnew("ordered");
for(i=1;i<=100;i++){
mystruct.insert("key#i#","val#i#")
}
function callback(key,val){
writeoutput(key & " " & val & "<br>")
}
mystruct.each(callback,false)
mystruct.each(callback,true);
mystruct.each(callback,true,10)
structeach(struct=mystruct,callback=callback,parallel=true,maxthreadcount=20)
structeach(struct=mystruct,callback=callback,parallel=true,maxthreadcount=40)
try{structeach(struct=mystruct,callback=callback,parallel=true,maxthreadcount=-20)}
catch(any e){
writeoutput("<br>Type: " & e.type & " Message:" & e.message )
}
try{
structeach(struct=mystruct,callback=callback,parallel=true,maxthreadcount="200")}
catch(any e){
writeoutput("<br>Type: " & e.type & " Message:" & e.message )
}
</cfscript>