Skip to main content

Splice List

Uncontrolled node

Overview

The Splice List node modifies a list by removing elements from a specified index and optionally inserting new elements. It implements JavaScript's splice method, allowing you to delete items from any position in the list and replace them with new values.

This node is useful for editing lists in place, removing specific ranges of elements, or inserting new data at precise positions within an array.

Inputs

InputTypeDescriptionDefault
ListDataThe list to be modified. Must be an array.-
StartNumberThe zero-based index at which to start changing the list. If negative, counts from the end of the list.0
Delete CountNumberThe number of elements to remove from the list starting at the index. If 0, no elements are removed.0
New ItemDataThe element to insert at the start index. If not provided, only deletion occurs.-

Outputs

OutputTypeDescription
OutputDataThe modified list after splicing operations.
DeletedDataAn array containing the elements that were removed from the original list.

Runtime Behavior and Defaults

The Splice List node executes immediately when its inputs change (uncontrolled behavior). It performs the following operations:

  • Validation: Checks if the input is a valid array. Returns an error object if the input is not a list.
  • Start Index: Converts to an integer. Negative values count from the end of the list (e.g., -1 starts at the last element).
  • Delete Count: Converts to an integer. Specifies how many items to remove from the start index.
  • Insertion: If a New Item is provided, it is inserted at the start index after deletion.

If Delete Count is 0 and no New Item is provided, the list remains unchanged. If New Item is provided without a Delete Count, the item is inserted at the start index without removing any existing elements.

Example

Scenario: Remove the first two items from a list and insert a new element at that position.

Inputs:

  • List: ["apple", "banana", "cherry", "date"]
  • Start: 0
  • Delete Count: 2
  • New Item: "elderberry"

Outputs:

  • Output: ["elderberry", "cherry", "date"]
  • Deleted: ["apple", "banana"]

Scenario: Remove an item from the middle of a list without inserting anything new.

Inputs:

  • List: [10, 20, 30, 40, 50]
  • Start: 2
  • Delete Count: 1

Outputs:

  • Output: [10, 20, 40, 50]
  • Deleted: [30]