ArrayReverse

Returns an array with all of the elements reversed.

The value in [0] within the input array will then exist in [n] in the output array, where n is the amount of elements in the array minus one.

Method Signature

ArrayReverse(array=[array])

Arguments

Argument
Type
Required
Description
Default

array

array

true

The array to reverse

Examples

Reverse an Array

Creates a new array with reversed positions

Run Example

myArray = [ 
	1,
	2,
	3
];
myArrayReversed = arrayReverse( myArray );
writeOutput( JSONSerialize( myArrayReversed ) );

Result: [3,2,1]

Reverse an Array via Member Function

Run Example

myArray = [ 
	1,
	2,
	3
];
writeOutput( JSONSerialize( myArray.reverse() ) );

Result: [3,2,1]

Reverse an Array using array slice syntax

Reverse an Array using array slice syntax adding in Boxlang 2018

myArray = [1,2,3]; 
writeOutput( serializeJSON( myArray[::-1] ) );

Result: [3,2,1]

Additional Examples

Run Example

numbers = [ 
	1,
	2,
	3,
	4
];
arrayReverse( numbers );
Dump( numbers ); // [4,3,2,1]
// member function
reversed = numbers.reverse();
Dump( reversed );

Last updated

Was this helpful?