$reverse
$reverse(array) -> arrayCompact type signature
<a:a>Source: JSONata
Documentation
Returns a new array with the input items in reverse order.
undefined input returns undefined. Arrays of length 0 or 1 are returned unchanged.
Examples
Reverse an array
Input
This example uses the patient-summary example input. The expression reads the tags array and reverses it.
Example input
JSON
{
"patientId": "pat-0001",
"name": {
"given": "Avery",
"family": "Reed",
"display": "Avery Reed"
},
"birthDate": "1990-06-12",
"sex": "female",
"primaryCareTeam": {
"organization": "ExampleCare",
"facility": "ExampleCare Clinic",
"practitioner": {
"practitionerId": "prac-4001",
"display": "Jordan Kim"
}
},
"identifiers": {
"memberId": "mbr-3001",
"recordNumber": "rec-5001"
},
"tags": [
"demo",
"fictional"
],
"_xmlTagName": "patientSummary"
}
Expression
$reverse(tags)
Result
["fictional", "demo"]