Join Two Arrays in ColdFusion

前端 未结 9 784
青春惊慌失措
青春惊慌失措 2020-12-29 19:22

Is there a built-in way to join two arrays in ColdFusion, similar to JavaScript\'s array.concat()?

相关标签:
9条回答
  • 2020-12-29 20:09

    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)

    0 讨论(0)
  • 2020-12-29 20:11

    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

    0 讨论(0)
  • 2020-12-29 20:14

    Yes, ColdFusion(10+) has an inbuilt function to append two arrays.

    Script version : array1.append(array2, true);

    Tag version: arrayAppend(array1, array2, true);

    0 讨论(0)
提交回复
热议问题