Search code examples
arrayscoldfusioncoldfusion-11

Appending an array to an array


I am trying to append the elements in an array to an existing (empty) array

if(attributes.list != "")           attributes.array.append(attributes.list.ListToArray());

What I get is something like

enter image description here

Is there a way to do this without having too loop through each item?


Solution

  • Use the optional merge parameter:

    If set to true, and value parameter is an array, appends array elements individually to the source array. If false (default) the complete array is added as one element at the end, in the source array. If value is not an array this argument is ignored.

    Setting merge=true will append the elements individually, rather appending the whole array as a single element:

    attributes.array.append(attributes.list.ListToArray(), true);
    

    ArrayAppend(array, merge) Example