ArrayPush
Adds an element or an object to the end of an array, then returns the size of the modified array.
Method Signature
ArrayPush(array=[modifiableArray], value=[any])
Arguments
Argument
Type
Required
Description
Default
array
modifiableArray
true
The array to which the element should be appended.
value
any
true
The element to append. Can be any type.
Examples
Push a value onto an array
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." );
Result: This array has 4 elements.
Member function version.
Using the member function. This version also works in ACF2018.
arr = [
1,
2,
3
];
al = arr.push( 42 );
writeOutput( "This array has " & al & " elements." );
Result: This array has 4 elements.
Push an object onto an array.
This demonstrates pushing an object onto an array.
arr = [
[
1
],
[
"two"
],
[
{
A : 3
}
]
];
al = arr.push( [
42
] );
writeOutput( "This array has " & al & " elements." );
Result: This array has 4 elements.
Additional Examples
numbers = [
1,
2,
3,
4
];
Dump( ArrayPush( numbers, 0 ) ); // Outputs 5
moreNumbers = [
5,
6,
7,
8
];
Dump( ArrayPush( moreNumbers, 4 ) );
// Outputs 5
Related
Last updated
Was this helpful?