ArrayShift()

Removes the first element of an array and returns the element that is removed. This method removes the element at the first index and shifts the values at consecutive indexes down. If you use ArrayShift in an empty array, you get an exception.

ArrayShift( array=array, defaultValue=any );

Returns: any

Argument Description
array
array, required

The array to shift.

defaultValue
any, optional

this value is returned in case the array is empty

Examples

numbers = [ 1, 2, 3, 4 ];
ArrayShift( numbers );
Dump( numbers ); // Outputs 1
moreNumbers = [ 5, 6, 7, 8 ];
ArrayShift( moreNumbers );
Dump( numbers ); // Outputs 5
numbers     = [ "one", "two", "three", "four" ];
ArrayShift( numbers);
Dump( numbers ); // Outputs one

See also