Back to Home
$jsonArrayReverse
$jsonArrayReverse reverses the order of a JSON array. The
last element becomes the first and vice versa.
Syntax
$jsonArrayReverse[Key;...]
-
Key: one or more keys forming the path to the array.
What happens
$jsonParseloads the JSON object.-
$jsonArrayReversereverses the order of the array at the given key path in place. -
Nothing is returned. Use
$jsonor$jsonJoinArrayto see the result.
Example 1: Reverse a simple array
$nomention
$jsonParse[{"fruits":["apple","orange","banana","grape"\]}]
$jsonArrayReverse[fruits]
$jsonJoinArray[fruits;, ]
What happens:
$jsonParseloads the object.$jsonArrayReverse[fruits]reverses the array.$jsonJoinArraydisplays the result.
Output:
grape, banana, orange, apple
Example 2: Sort descending by combining with sort
$nomention
$jsonParse[{"scores":[10,30,50,70,90\]}]
$jsonArrayReverse[scores]
Descending: $jsonJoinArray[scores;, ]
What happens:
$jsonParseloads the already-sorted scores.-
$jsonArrayReverse[scores]flips the order to descending. $jsonJoinArraydisplays the result.
Output:
Descending: 90, 70, 50, 30, 10
Common uses
-
Descending sort: use after
$jsonArraySortto get highest-to-lowest order - Reversing a history: show the most recent entries first
- Flipping a list: reverse any ordered array
See also
- $jsonArraySort: to sort before reversing for descending order
- $jsonJoinArray: to display the reversed array as a string