Skip to main content

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:

  1. Receives an array through the Array input
  2. Validates that the array is not null
  3. If the array is empty, returns the empty array and null for the element
  4. If the array has elements, removes the last element
  5. Returns the removed element through the Element output
  6. Returns the modified array (with last element removed) through the Array output
  7. 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:

  1. Array: ["Task A", "Task B", "Task C", "Task D"]
  2. Pop → Element: "Task D", Array: ["Task A", "Task B", "Task C"]
  3. Process the element "Task D"
  4. Pop again → Element: "Task C", Array: ["Task A", "Task B"]
  5. Continue until array is empty

Example 2: Undo Last Action

Remove the most recent entry from a history:

  1. Array: {{flow.actionHistory}} = ["Login", "Search", "Edit", "Delete"]
  2. Pop → Element: "Delete", Array: ["Login", "Search", "Edit"]
  3. The last action "Delete" is removed and can be logged or used for undo functionality
  4. Updated history stored back to {{flow.actionHistory}}

Example 3: Batch Processing with Progress

Process items from the end of a list:

  1. Get all pending items in {{flow.pendingItems}}
  2. 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:

  1. Array: {{msg.entries}} = [101, 102, 103, 104]
  2. Pop → Element: 104, Array: [101, 102, 103]
  3. The latest entry (104) is removed
  4. Can be used for rollback scenarios or removing duplicate entries

Example 5: Extract Configuration Overrides

Process configuration layers from most specific to least specific:

  1. Array: {{flow.configLayers}} = ["default", "environment", "user", "override"]
  2. Pop → Element: "override", Array: ["default", "environment", "user"]
  3. Apply override settings first
  4. 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

OperationPopShift
Removes fromEnd of arrayBeginning of array
Processing orderLIFO (Last-In-First-Out)FIFO (First-In-First-Out)
Use caseStack, reverse processingQueue, sequential processing
ExampleUndo last actionProcess 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}}