Skip to main content
Flatten Block Screenshot

Overview

The Flatten Block is designed to simplify complex nested array structures by flattening them into a single-level array. This block is particularly useful when dealing with multi-dimensional arrays or when you need to process all elements of a nested structure in a linear fashion.

Key Features

  • Flattens nested arrays one level deep
  • Preserves the order of elements from the original nested structure
  • Handles arrays containing both nested arrays and non-array elements

Inputs

input
any[][]
required
The nested array structure to be flattened. Must be a nested array (array of arrays). Non-nested arrays or other types will result in an error.

Outputs

output
any[]
The resulting flattened array containing all elements from the input, with one level of nesting removed.

Example: Flattening a Nested Array

  1. Create an Array Block with a nested array structure, e.g., [[1, 2], [3, 4], [5, 6]].
  2. Add a Flatten Block and connect the Array Block to its input.
  3. Run the flow. The Flatten Block’s output will be [1, 2, 3, 4, 5, 6].

Error Handling

  • If no input is provided, the block will error with “Input is required”
  • If the input is not a nested array (array of arrays), the block will error with “Input is not a nested array”
  • The block will only flatten one level deep - for deeper nesting, multiple Flatten blocks can be chained

FAQ

No, the Flatten Block is designed to work only with nested arrays. It will error if given objects or other non-array inputs.
The Flatten Block only flattens one level deep. For example, [[1, [2, 3]], [4, 5]] becomes [1, [2, 3], 4, 5]. To flatten deeper levels, chain multiple Flatten blocks together.

See Also

I