arrayAppend

Appends an element to the end of an array.

arrayAppend(array, value [, merge]) → returns boolean

Member Function Syntax

someArray.append(value [, merge])

Argument Reference

array array
Required

The array to which the element should be appended.

value any
Required

The element to append. Can be any type.

merge boolean
Default: false

CF 10+ When true appends array elements individually to the specified array. When false (default), the new array is appended as a single element.
Values:
  • true
  • false

Compatibility

Lucee:

When called as a member function array.append() returns the array instead of boolean.

Examples
Sample code invoking the arrayAppend function

Uses the arrayAppend function to append a value to the end of the array

someArray = [1,2,3];
arrayAppend(someArray, 4);
writeOutput(serializeJSON(someArray));

Expected Result: [1,2,3,4]

CF 11+ Lucee 4.5+ Invoking the append function on an array is the same as running arrayAppend.

someArray = [1,2,3];
someArray.append(4);
writeOutput(serializeJSON(someArray));

Expected Result: [1,2,3,4]

CF 10+ You can merge two arrays when third parameter is set to true.

someArray = [1,2,3];
ArrayAppend(someArray,[4,5,6],true);
writeDump(serializeJSON(someArray));

Expected Result: [1,2,3,4,5,6]

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub