Not yet rated
Tags:

Problem

You have two arrays that you want to merge into one single array, but don't want to loop through one of the arrays and append each element to the second array for performance reasons.

Solution

Because Coldfusion is built on top of java we can take advantage of some of the java methods. One of these is addAll(), which merges two arrays together.

Detailed explanation

<!--- 
create two arrays for demonstrate with
--->
<cfset myArrayA = ['one','two','three']>
<cfset myArrayB = ['four','five','six']>

<!--- 
Add all the elements in Array B to Array A
--->
<cfset myArrayA.addAll( myArrayB )>

<!---
Display the result 
--->
<cfdump var="#myArrayA#">

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes