Is there a built-in way to join two arrays in ColdFusion, similar to JavaScript\'s array.concat()
?
In CF 10 or Railo 4, you can use the concat() function of the Underscore.cfc library to get a new array that is a concatenation of two other arrays (without modifying the existing arrays). Example cfscript:
newArray = _.concat([1], [2]);
Result:
// newArray == [1, 2]
Using this method to get a new array is a bit cleaner than creating a new array and calling ArrayAppend on it twice.
(Disclaimer: I wrote Underscore.cfc)
Not really, but guess what, just use Java! :)
<cfset foo = [1,2,3]>
<cfset bar = [4,5,6]>
<cfset foo.addAll( bar )>
reference: Java's Collection Interface API.
source: http://www.aliaspooryorik.com/blog/index.cfm/e/posts.details/post/merging-two-arrays-267
Yes, ColdFusion(10+) has an inbuilt function to append two arrays.
Script version : array1.append(array2, true);
Tag version: arrayAppend(array1, array2, true);