Join Two Arrays in ColdFusion

前端 未结 9 847
青春惊慌失措
青春惊慌失措 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)

提交回复
热议问题