JSON TransformArray
reverse
Reverse the order of array elements
reverse
Reverses the order of all elements in an array.
Options
This operation takes no options; pass an empty object or omit options entirely.
Example
Input
[1, 2, 3, 4]Operation
{ "type": "reverse" }Output
[4, 3, 2, 1]In a Circuit Step
{
"name": "reverse_history",
"description": "Reverse the order of messages so the newest is first",
"function": "circuit.core.transform.json",
"input": {
"source": "${{ messages }}",
"operations": [
{ "type": "reverse" }
]
},
"outputs": [
{
"name": "reversed_messages",
"description": "Messages in reverse chronological order",
"value": "${{ reverse_history.output.transformed_result }}"
}
]
}Notes & gotchas
- Errors with
reverse: expected arrayif the input is not an array. - Returns a new array; the original is not mutated.
- Pairs well with
sortwhen you want descending order on a non-string key without specifying"order": "desc".