Is there a built-in way to join two arrays in ColdFusion, similar to JavaScript's array.concat()
?
views:
197answers:
3
+7
A:
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
Henry
2010-06-21 02:13:17
Oddly enough, underlying Java methods do not work always as expected. I still haven't figure out exactly when and why. I often use Java methods for removing duplicates, joining and sorting Arrays, I remember sometimes it didn't work depending how you create arrays, which operations you perform before calling Java method etc. So pay attention!
zarko.susnjar
2010-06-22 19:19:32
+2
A:
If you're using Railo, you can use ArrayMerge (E.g. <cfset NewArray=ArrayMerge(FirstArray,SecondArray)>
).
Gert G
2010-06-21 02:55:29
I've added to Adobe's ColdFusion Bug Tracker as feature request at http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=83397 . Vote it up! :)
Henry
2010-06-21 03:10:38
ArrayConcat Vs. ArrayMerge Vs ArrayAppend ? Please discuss here: http://groups.google.com/group/cfml-conventional-wisdom/browse_thread/thread/95a4b511128c37ae
Henry
2010-06-21 18:59:36
A:
In javascript array.join(s) creates a string out of all of the elements of the array separated by the delimiter s. A similar function to this in ColdFusion is the ArrayToList function. As far as appending an array to another I don't believe there is a CF function for that. Check http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_03.html#3473387 to see the list of Array functions in CF. Or try something like this:
<cfscript> for(index = 1; index LTE ArrayLen(array2); i = i + 1) { ArrayAppend(array1, array2[i]); } </cfscript>
Joel Anderson
2010-06-23 21:44:05