Pop
Removes and returns the last element from 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 remove the last element from.
Outputs
- Element - The removed last element from the array.
- Array - The modified array with the last element removed.
How It Works
The Pop node removes the last element from an array and returns both the removed element and the modified array. When executed, the node:
- Receives an array through the Array input
- Validates that the array is not null
- If the array is empty, returns the empty array and null for the element
- If the array has elements, removes the last element
- Returns the removed element through the Element output
- Returns the modified array (with last element removed) through the Array output
- Handles thread-safe operations when working with Global or Flow scope variables
Requirements
- Valid array as input (not null)
- Empty arrays are valid but will return null for the element
Error Handling
The node will return specific errors in the following cases:
- Array is null: "Array cannot be null"
Usage Examples
Example 1: Process Tasks in Reverse Order (Stack/LIFO)
Implement Last-In-First-Out (LIFO) processing:
- Array:
["Task A", "Task B", "Task C", "Task D"] - Pop → Element:
"Task D", Array:["Task A", "Task B", "Task C"] - Process the element "Task D"
- Pop again → Element:
"Task C", Array:["Task A", "Task B"] - Continue until array is empty
Example 2: Undo Last Action
Remove the most recent entry from a history:
- Array:
{{flow.actionHistory}}=["Login", "Search", "Edit", "Delete"] - Pop → Element:
"Delete", Array:["Login", "Search", "Edit"] - The last action "Delete" is removed and can be logged or used for undo functionality
- Updated history stored back to
{{flow.actionHistory}}
Example 3: Batch Processing with Progress
Process items from the end of a list:
- Get all pending items in
{{flow.pendingItems}} - Loop while array is not empty:
a. Pop → get last item and reduced array
b. Process the item
c. Update
{{flow.pendingItems}}with the reduced array d. Continue until all items processed
Example 4: Remove Latest Entry
Remove the most recently added element:
- Array:
{{msg.entries}}=[101, 102, 103, 104] - Pop → Element:
104, Array:[101, 102, 103] - The latest entry (104) is removed
- Can be used for rollback scenarios or removing duplicate entries
Example 5: Extract Configuration Overrides
Process configuration layers from most specific to least specific:
- Array:
{{flow.configLayers}}=["default", "environment", "user", "override"] - Pop → Element:
"override", Array:["default", "environment", "user"] - Apply override settings first
- Continue popping to apply each layer in reverse priority order
Tips for Effective Use
- Stack behavior: Pop implements LIFO (Last-In-First-Out) - opposite of Shift which is FIFO
- Empty arrays: Popping from an empty array returns null for element, not an error
- Original array is modified: The returned array has one less element
- Use in loops to process all elements from end to beginning
- Combine with Push for stack data structure implementation
- Store the returned array back to the original variable to maintain state
- Use Array.GetLength first to check if array has elements before popping
- For large arrays, consider the performance of repeated pop operations
- Thread-safe when using Global or Flow scopes
- The removed element can be any data type
Common Use Cases
- Implementing LIFO (stack) data structures
- Processing items in reverse order
- Undo/redo functionality (removing last action)
- Removing the most recent entry from a list
- Batch processing from the end of a queue
- Reversing the order of processing
- Removing temporary or provisional data
- History management (removing latest history entry)
- Cleanup operations (removing most recent additions)
- Implementing depth-first search algorithms
Difference Between Pop and Shift
| Operation | Pop | Shift |
|---|---|---|
| Removes from | End of array | Beginning of array |
| Processing order | LIFO (Last-In-First-Out) | FIFO (First-In-First-Out) |
| Use case | Stack, reverse processing | Queue, sequential processing |
| Example | Undo last action | Process oldest request first |
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 before popping
- Add null checking before calling Pop
Integration Examples
Example: Stack-Based Processing
1. Initialize stack: ["Item1", "Item2", "Item3"]
2. While stack is not empty:
a. Pop → get element and reduced stack
b. Process element
c. Update stack variable
3. All items processed in LIFO order
Example: Safe Pop with Validation
1. Get array: {{flow.items}}
2. Use Get Length to check size
3. If length > 0:
a. Pop → get last element
b. Process element
c. Update array
4. If length = 0:
a. Skip pop operation
b. Log "No items to process"
Example: Combine with Push for Stack Operations
Push operation:
1. Get current stack: {{flow.stack}}
2. Use Push to add new item
3. Update {{flow.stack}}
Pop operation:
1. Get current stack: {{flow.stack}}
2. Use Pop to remove and get last item
3. Process the item
4. Update {{flow.stack}}