Let’s say you have 2 arrays and you would like merge the two into one array.
You can do it the long way by looping over the arrays or even better, you can use this simple ColdFusion function I have put together.
<cffunction name=”arrayMerge” access=”public” returntype=”array” output=”false” hint=”Appends array2 to array1 and returns merged array”>
<cfargument name=”array1″ required=”true” type=”array”>
<cfargument name=”array2″ required=”true” type=”array”>
<cfset var a1 = arguments.array1>
<cfset a1.addAll(arguments.array2)>
<cfreturn a1 />
</cffunction>
Sweet.
Where in the CF reference is array.addAll() documented? I found a Flex reference in the mx.collections that looks like an equivalent to ListAppend.
Hi Gordon,
Since ColdFusion is built on Java, this allows us to take advantage of the underlying Java functions.
Have a look at the Java 6 docs on http://download.oracle.com/javase/6/docs/api/java/util/Collection.html#addAll%28java.util.Collection%29 to find out more about the addAll function and a bunch of other Java functions you can use.