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
myArray = [
1,
2,
3
];
myArrayReversed = arrayReverse( myArray );
writeOutput( JSONSerialize( myArrayReversed ) );
Result: [3,2,1]
Reverse an Array via Member Function
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
numbers = [
1,
2,
3,
4
];
arrayReverse( numbers );
Dump( numbers ); // [4,3,2,1]
// member function
reversed = numbers.reverse();
Dump( reversed );
Related
Last updated
Was this helpful?