Skip to main content

Flatten List

Uncontrolled node

Overview

The Flatten List node converts a nested list structure into a single-level list by removing one or more levels of nesting. This is useful when processing data that arrives as nested arrays (such as results from batch operations or grouped data) that need to be treated as a single continuous sequence.

For example, given the input [[1, 2], [3, 4]], the node outputs [1, 2, 3, 4].

Depth Control

The node flattens lists recursively based on the Depth setting:

  • Depth 1 (default): Flattens one level of nesting. [[1, 2], [3, 4]][1, 2, 3, 4]
  • Depth 2: Flattens two levels. [[[1, 2]], [[3, 4]]][1, 2, 3, 4]
  • Higher depths continue flattening deeper nested structures.

Inputs

InputTypeDescriptionDefault
ListListThe nested list to flatten. If not a list, returns the input unchanged.-
DepthNumberHow many levels of nesting to flatten. Must be ≥ 1.1

Outputs

OutputTypeDescription
OutputListThe flattened list with nesting removed up to the specified depth.

Runtime Behavior and Defaults

The Flatten List node is uncontrolled, meaning it executes automatically whenever its input data changes without requiring an event trigger.

  • Default Depth: If not specified or invalid, depth defaults to 1
  • Non-list Input: If the input is not an array or is empty, it returns the input unchanged
  • Depth Validation: The depth value is rounded down to the nearest integer. Values less than 1 are treated as 1
  • Implementation: Uses JavaScript's Array.prototype.flat() method internally

Example

Basic Flattening

Flatten a list of grouped items into a single sequence:

Input List: [[1, 2], [3, 4], [5, 6]]
Depth: 1
Output: [1, 2, 3, 4, 5, 6]

Deep Nesting

Flatten a doubly-nested structure:

Input List: [[[1, 2]], [[3, 4]]]
Depth: 2
Output: [1, 2, 3, 4]

Shallow Flattening

Only flatten the first level, keeping some nesting:

Input List: [[[1, 2]], [[3, 4]]]
Depth: 1
Output: [[1, 2], [3, 4]] (only the outer array is flattened)