Remove Element
Removes an element from an array by index position or by matching value.
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.
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 an element from.
- Element Index - (Optional) The zero-based index of the element to remove.
- Element - (Optional) The value to search for and remove from the array.
You must provide either Element Index OR Element, but not both. If you provide an index, the element at that position will be removed. If you provide a value, the first matching element will be removed.
Outputs
- Array - The modified array with the specified element removed.
How It Works
The Remove Element node removes an element from an array using either an index or a matching value. When executed, the node:
- Receives an array through the Array input
- Validates that the array is not null
- Receives either an index or an element value (at least one must be provided)
- If using index: a. Validates the index is within valid bounds b. Removes the element at that position
- If using element value: a. Searches for the first element matching the value b. Removes the first match found
- Returns the modified array with the element removed
Requirements
- Valid array as input (not null)
- Either Element Index OR Element must be provided
- If using index: must be 0 or greater and < array length
- If using element: the value must exist in the array
Error Handling
The node will return specific errors in the following cases:
- Array is null: "Array cannot be null"
- Index is negative: "Index cannot be less than 0"
- Index is too large: "Index X cannot be larger than the array length Y"
- Neither index nor element provided: "Either index or element has to be given"
- Element value not found: "element not found"
Removal Methods
Method 1: Remove by Index
Removes the element at a specific position:
Array: ["apple", "banana", "orange", "grape"]
Index: 1
Result: ["apple", "orange", "grape"]
Method 2: Remove by Value
Removes the first element matching the value:
Array: ["apple", "banana", "orange", "banana"]
Element: "banana"
Result: ["apple", "orange", "banana"]
Note: Only the first "banana" is removed
Usage Examples
Example 1: Remove Item by Position
Remove the third item from a list:
- Array:
["Item1", "Item2", "Item3", "Item4"] - Element Index:
2(zero-based, so this is the third item) - Result:
["Item1", "Item2", "Item4"]
Example 2: Remove Failed Task
Remove a specific task by name:
- Array:
{{flow.tasks}}=["Login", "Process", "Invalid", "Logout"] - Element:
"Invalid" - Result:
["Login", "Process", "Logout"] - The failed task is removed from the list
Example 3: Delete Customer by Index
Remove a customer at a dynamic index:
- Array:
{{msg.customers}} - Element Index:
{{msg.selectedIndex}} - Result: Customer at the selected index is removed
- Useful for user-driven deletions
Example 4: Remove Duplicate Entry
Remove the first occurrence of a duplicate value:
- Array:
[101, 102, 103, 102, 104] - Element:
"102" - Result:
[101, 103, 102, 104] - Only the first 102 is removed
Example 5: Clean Invalid Data
Remove invalid entries during data processing:
- Process data item by item
- When invalid item detected:
a. Get item value →
{{msg.invalidItem}}b. Remove Element with Element ={{msg.invalidItem}} - Result: Array with invalid items removed
Example 6: Remove Last Processed Item
Remove an item after processing in a loop:
- Get array:
{{flow.pendingItems}} - Process first item (index 0)
- Remove Element with Index = 0
- Update
{{flow.pendingItems}} - Repeat until array is empty
Tips for Effective Use
- Use index when you know the exact position
- Use element value when you know the content but not the position
- Zero-based indexing: First element is at index 0
- First match only: When removing by value, only the first match is removed
- Index validation: Use Array.GetLength to validate index before removal
- To remove all occurrences of a value, use in a loop with element removal
- The original array is modified and returned
- Combine with Array.GetElement to verify what will be removed
- For multiple removals, process from highest index to lowest to avoid index shifting issues
Common Use Cases
- Removing invalid or failed items from processing lists
- Deleting user-selected items from lists
- Cleaning data by removing unwanted values
- Removing processed items from queues
- Filtering out error records from datasets
- Implementing deletion functionality in workflows
- Removing temporary or placeholder values
- Cleaning up duplicate entries
- Managing dynamic task lists
- Implementing undo functionality (remove last action)
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
Error: "Index cannot be less than 0"
Cause: The index value is negative.
Solutions:
- Ensure index variables are initialized with valid values (0 or greater)
- Add validation before removal
- Check calculation logic if using dynamic indices
Error: "Index X cannot be larger than the array length Y"
Cause: The index exceeds the maximum valid position in the array.
Solutions:
- Use Array.GetLength to determine array size first
- Add validation:
if (index < arrayLength) then remove - For last element, use index = (length - 1)
- Account for array size changes in loops
Error: "Either index or element has to be given"
Cause: Neither Element Index nor Element was provided.
Solutions:
- Provide at least one input: either Element Index or Element
- Check that variable names are correct
- Verify the input is properly set in the node configuration
Error: "element not found"
Cause: The specified element value doesn't exist in the array.
Solutions:
- Verify the element value matches exactly (case-sensitive for strings)
- Use Array.GetElement in a loop to check array contents first
- Add error handling to gracefully handle missing elements
- Use Continue On Error if the element might not exist
Integration Examples
Example: Safe Removal with Validation
1. Get array: {{flow.items}}
2. Get index to remove: {{msg.removeIndex}}
3. Use Array.GetLength → {{msg.arrayLength}}
4. Validate: If {{msg.removeIndex}} < {{msg.arrayLength}}:
a. Remove Element with Index = {{msg.removeIndex}}
b. Update {{flow.items}}
5. Otherwise:
a. Log error: "Invalid index"
Example: Remove All Occurrences of Value
1. Get array: {{flow.data}}
2. Get value to remove: {{msg.removeValue}}
3. Loop:
a. Try to remove element with Element = {{msg.removeValue}}
b. If successful, continue loop
c. If "element not found" error, exit loop
4. Result: All occurrences removed
Example: Process and Remove Pattern
1. Get array: {{flow.tasks}}
2. While array is not empty:
a. Get first element (index 0) → {{msg.currentTask}}
b. Process {{msg.currentTask}}
c. Remove Element with Index = 0
d. Update {{flow.tasks}}
3. Result: All tasks processed and removed
Example: Conditional Removal
1. Get array: {{msg.items}}
2. Get array length → {{msg.count}}
3. For i = 0 to {{msg.count}} - 1:
a. Get element at index i → {{msg.item}}
b. Check condition (e.g., item.status === "invalid")
c. If condition is true:
- Remove Element with Index = i
- Decrement i (because array shifted)
- Update array
4. Result: All items meeting condition are removed