Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes and Ezra Parker and Dan Wilson and John Mason and Jason Dean and Luis Majano and Mark Mandel and Brian Kotek and Wil Genovese and Rob Brooks-Bilson and Andy Matthews and Simeon Bateman and Ray Camden and Chris Rockett and Joe Bernard and Dan Skaggs and Byron Raines and Barney Boisvert and Simon Free and Steve 'Cutter' Blades and Seth Bienek and Katie Bienek and Jeff Coughlin
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes@doughughes ) , Ezra Parker , Dan Wilson@DanWilson ) , John Mason@john_mason_ ) , Jason Dean@JasonPDean ) , Luis Majano@lmajano ) , Mark Mandel@Neurotic ) , Brian Kotek , Wil Genovese@wilgeno ) , Rob Brooks-Bilson@styggiti ) , Andy Matthews@commadelimited ) , Simeon Bateman@simBateman ) , Ray Camden@cfjedimaster ) , Chris Rockett ( @RockettMan ) , Joe Bernard@JEBernard ) , Dan Skaggs@dskaggs ) , Byron Raines ( @byronraines ) , Barney Boisvert@barneyb ) , Simon Free@simonfree ) , Steve 'Cutter' Blades@cutterbl ) , Seth Bienek@sethbienek ) , Katie Bienek@KatieBienek ) , and Jeff Coughlin@jeffcoughlin )

ColdFusion Array Loop Works With ARGUMENTS

By Ben Nadel on
Tags: ColdFusion

As a quick follow up to my post yesterday on using ColdFusion 8's new array iteration via CFLoop, I thought I would check to see if array iteration worked on another "pseudo array", the function ARGUMENTS scope. The ARGUMENTS scope is a very interesting object that has both struct and array properties, meaning, it can be accessed both by key and by index value. As this object only has array-like behavior and is not a true array, it is not clear as to how much array manipulation will be possible. To test this, all I did was set up a function that takes its ARGUMENTS scope and loops over it, CFDumping out each value:

  • <cffunction
  • name="LoopArguments"
  • access="public"
  • returntype="void"
  • output="true"
  • hint="Iterates over the arguments array.">
  •  
  • <!--- Define the local scope. --->
  • <cfset var LOCAL = {} />
  •  
  • <!--- Iterate over the arguments as if it were an array. --->
  • <cfloop
  • index="LOCAL.Value"
  • array="#ARGUMENTS#">
  •  
  • <!--- Dump out data element. --->
  • <cfdump
  • var="[#LOCAL.Value#]"
  • label="ARGUMENTS Data Point"
  • />
  •  
  • </cfloop>
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>

In the CFDump tag, I am including the brackets for visible value deliniation; this means that only string values can be passed to the function, but this should work the same, functionally, with any type of value. Now, we just run the code:

  • <!--- Call function with various values. --->
  • <cfset LoopArguments(
  • "Itty",
  • "Bitty",
  • "Kitty",
  • "Club"
  • ) />

It works perfectly, giving us the CFDump output:

[Itty] [Bitty] [Kitty] [Club]

Cool; ColdFusion 8's new array iteration works fine with the array-like behavior of the ARGUMENTS scope.

Tweet This Groovy post by @BenNadel - ColdFusion Array Loop Works With ARGUMENTS Thanks my man — you rock the party that rocks the body!



Reader Comments

I'd like to see you turn your prodigious investigative powers to what does and does not work with the cfscript loop:

for (i in someVar) { ... }

I know it works for structs (I use it a lot), but what else works with it.

@Sean,

Not a bad idea. I rarely play around with CFScript, so it would be good to do some snooping. I know that you can finally use things like >= and <. Let me see what I can find out.