Reverse
Reverses the order of elements in an array.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Array - The array to reverse.
Outputs
- Array - The array with elements in reversed order.
How It Works
The Reverse node reverses the order of elements in an array. When executed, the node:
- Receives an array through the Array input
- Validates that the array is not null
- Reverses the order of elements (first becomes last, last becomes first)
- Returns the reversed array through the Array output
Requirements
- Valid array as input (not null)
Error Handling
The node will return specific errors in the following cases:
- Array is null: "Array cannot be null"
Usage Examples
Example 1: Reverse Processing Order
Process items in reverse chronological order:
- Array:
["Oldest", "Older", "Recent", "Newest"] - Reverse → Result:
["Newest", "Recent", "Older", "Oldest"] - Process items starting with "Newest"
- Useful for handling most recent items first
Example 2: Reverse Search Results
Display search results in reverse order:
- Array:
{{msg.searchResults}}=[result1, result2, result3, result4] - Reverse → Result:
[result4, result3, result2, result1] - Display results with most recent or highest ranked first
- Store reversed results to
{{msg.reversedResults}}
Example 3: Create Countdown List
Convert ascending numbers to descending:
- Array:
[1, 2, 3, 4, 5] - Reverse → Result:
[5, 4, 3, 2, 1] - Use for countdown sequences or reverse iterations
Example 4: Reverse Breadcrumb Trail
Build navigation path from end to start:
- Array:
["Home", "Products", "Electronics", "Laptops"] - Reverse → Result:
["Laptops", "Electronics", "Products", "Home"] - Use for building reverse navigation or backtracking
Example 5: LIFO to FIFO Conversion
Convert stack order to queue order:
- Array: Items added in LIFO order
- Reverse → Result: Items now in FIFO order
- Process in the opposite order from how they were added
Example 6: Reverse Sorted Data
Quickly change sort direction:
- Sort array in ascending order:
[10, 20, 30, 40, 50] - Reverse → Result:
[50, 40, 30, 20, 10](descending order) - Alternative to sorting with custom comparators
Tips for Effective Use
- In-place operation: The original array is modified and returned reversed
- Works with any data type: strings, numbers, objects, arrays, or booleans
- Empty arrays: Reversing an empty array returns an empty array (no error)
- Single element: Reversing a single-element array returns the same array
- Efficient operation with minimal overhead
- Use twice to restore original order
- Combine with Sort for descending order sorting
- Perfect for changing processing direction
- Use for stack-to-queue conversions
- Can be used as part of data transformation pipelines
Common Use Cases
- Processing items in reverse chronological order
- Converting LIFO (Last-In-First-Out) to FIFO (First-In-First-Out)
- Displaying results in reverse order
- Creating descending order from ascending sort
- Reversing navigation paths or breadcrumbs
- Building countdown sequences
- Implementing reverse iteration patterns
- Creating mirror or palindrome data
- Reversing the order of scraped data
- Changing priority order (lowest to highest becomes highest to lowest)
Integration Examples
Example: Process Most Recent First
1. Get chronologically ordered data: {{flow.items}}
(e.g., ["Jan", "Feb", "Mar", "Apr"])
2. Reverse → Result: ["Apr", "Mar", "Feb", "Jan"]
3. Process in a loop starting with most recent
4. Store results to {{flow.processedItems}}
Example: Descending Sort Pattern
1. Sort array in ascending order using Array.Sort
Result: [10, 20, 30, 40, 50]
2. Reverse the sorted array
Result: [50, 40, 30, 20, 10]
3. Now you have descending order
Example: Reverse Navigation Breadcrumb
1. Build breadcrumb array: ["Home", "Category", "Subcategory", "Product"]
2. Reverse → ["Product", "Subcategory", "Category", "Home"]
3. Use for back-navigation logic
4. Each element represents the previous page to navigate to
Example: Priority Reversal
1. Items ordered by priority (low to high): [
{id: 1, priority: 1},
{id: 2, priority: 2},
{id: 3, priority: 3}
]
2. Reverse array to process high priority first
3. Result: [
{id: 3, priority: 3},
{id: 2, priority: 2},
{id: 1, priority: 1}
]
4. Process starting with highest priority
Example: Undo Operation
1. Get action history: ["Action1", "Action2", "Action3"]
2. Reverse → ["Action3", "Action2", "Action1"]
3. Process undo in reverse order
4. Most recent action (Action3) is undone first
Example: Compare Original vs Reversed
1. Store original array: {{flow.original}}
2. Reverse the array → {{flow.reversed}}
3. Check if array is palindrome:
a. Compare {{flow.original}} with {{flow.reversed}}
b. If equal, array is a palindrome
4. Use for data validation or pattern detection
Common Errors and Solutions
Error: "Array cannot be null"
Cause: The array input is null or undefined.
Solutions:
- Verify that the array variable exists and is initialized
- Check that previous nodes successfully created the array
- Use Array.Assign to initialize arrays if needed
- Add null checking before calling Reverse
Performance Notes
- Reverse is an efficient in-place operation
- Time complexity: O(n/2) where n is array length
- No additional memory allocation required
- Works efficiently with large arrays
- Single pass through half the array is sufficient
Restore Original Order
To restore the original order after reversing:
1. Original: [1, 2, 3, 4, 5]
2. First Reverse: [5, 4, 3, 2, 1]
3. Second Reverse: [1, 2, 3, 4, 5]
(back to original order)
Simply reverse the array again to return to the original sequence.