In Railo 4.0 we have expanded the capabilities of using the cfscript syntax. As part of this we devoted some attention to how you can loop through collections using the for(x in y){} syntax.
We have also changed how we loop over queries, now giving you access to the row itself!
Let's check out some examples, first up looping through a structure:
myStruct = {one: "The One" ,two: "The Two",three: "The Three",four:"The Four",five: "The Five"};
for(key in myStruct){
dump(key);
}
This dumps out the following:
We can do this for arrays too!
myArray = ListToArray("one,two,three,four,five");
for(item in myArray){
dump(item);
}
This dumps out the following:
And finally, we don't forget Queries! (notice the creation syntax! Lovely!)
myQuery = Query("id":[1,2,3,4,5],value:[1,2,3,4,5]);
for(row in myQuery){
dump(row);
}
This dumps out the following: