ArrayPop

Remove last item in array and return it

Method Signature

ArrayPop(array=[modifiablearray], defaultValue=[any])

Arguments

Argument
Type
Required
Description
Default

array

modifiablearray

true

The array to get the last

defaultValue

any

false

Examples

Remove the last value from an array

This is the full function version of arrayPop to remove the last value of an array.

Run Example

arr = [ 
	1,
	2,
	42
];
p = arrayPop( array=arr );
writeOutput( p );

Result: 42

Member function version.

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

Run Example

arr = [ 
	1,
	2,
	42
];
p = arr.pop();
writeOutput( p );

Result: 42

Additional Examples

Run Example

numbers = [ 
	1,
	2,
	3,
	4
];
dump( ArrayPop( numbers ) ); // Outputs 4
dump( numbers ); // Outputs [ 1, 2, 3 ]
moreNumbers = [
	5,
	6,
	7,
	8
];
dump( ArrayPop( moreNumbers, 4 ) ); // Outputs 8
dump( moreNumbers );
 // Outputs [ 5, 6, 7 ]

Last updated

Was this helpful?