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 for the arrayAppend function

array

Required: Yes
The array to which the element should be appended.

value

Required: Yes
The element to append. Can be any type.

merge

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

Compatibility

Lucee:

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

Examples sample code invoking the arrayAppend function


Append a value to an array

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]


Append a value to an array using the Array member function

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]


Fork me on GitHub