Have you ever wanted a quick and easy way to combine arrays in ColdFusion. I have done this a number of ways in the best, but came across this gem and thought I would share.
All ColdFusion arrays are of the Java vector type, we can use the underlying java.util.Vector class methods, specifically the addAll() method.
Keep in mind that this is not a "documented" use of arrays in ColdFusion, so at any version it may stop working.
Merging two arrays in ColdFusion with the java.util.vector.addAll()
ar1 = ["a","b","c"];
ar2 = ["d","e","f"];
ar1.addAll(ar2);
writeDump(ar1);
Add Your Comment
(1)
Dec 10, 2010 10:43:30 UTC
by Adam lewis
Thanks for the coding nugget. That pretty slick.