arrayPush

Adds an element or an object to the end of an array, then returns the size of the modified array.

arrayPush(array, value) → returns numeric

Member Function Syntax

array.push(value)

arrayPush Argument Reference

array array
Required

Array to which a value or object is to be added.

value any
Required

The value or object to be added to the array.

Compatibility

ColdFusion:

Version 2021+ The full function was added in ACF 2021, but the member function appears to work in ACF 2018 (likely using Java).

Links more information about arrayPush

Examples sample code invoking the arrayPush function

This is the full function version of arrayPush to push a value onto the end of the array.

arr=[1,2,3] ;
ArrayPush(array=arr,value=42) ;
WriteOutput('This array has ' & arrayLen(arr) & ' elements.') ;

Expected Result: This array has 4 elements.

Using the member function. This version also works in ACF2018.

arr=[1,2,3];
al=arr.push(42);
WriteOutput('This array has ' & al & ' elements.');

Expected Result: This array has 4 elements.

This demonstrates pushing an object onto an array.

arr=[ [1],['two'],[{a:3}]];
al=arr.push([42]);
WriteOutput('This array has ' & al & ' elements.');

Expected Result: This array has 4 elements.


Fork me on GitHub