Loading

Back to Home

$jsonArrayReverse

$jsonArrayReverse reverses the order of a JSON array. The last element becomes the first and vice versa.

Syntax

$jsonArrayReverse[Key;...]

What happens

  1. $jsonParse loads the JSON object.
  2. $jsonArrayReverse reverses the order of the array at the given key path in place.
  3. Nothing is returned. Use $json or $jsonJoinArray to see the result.

Example 1: Reverse a simple array

$nomention
$jsonParse[{"fruits":["apple","orange","banana","grape"\]}]
$jsonArrayReverse[fruits]
$jsonJoinArray[fruits;, ]

What happens:

  1. $jsonParse loads the object.
  2. $jsonArrayReverse[fruits] reverses the array.
  3. $jsonJoinArray displays 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:

  1. $jsonParse loads the already-sorted scores.
  2. $jsonArrayReverse[scores] flips the order to descending.
  3. $jsonJoinArray displays the result.

Output:

Descending: 90, 70, 50, 30, 10

Common uses

See also