Modifier Blocks
Flatten Block
Flatten nested arrays into a single-level array
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
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
The resulting flattened array containing all elements from the input, with one level of nesting removed.
Example: Flattening a Nested Array
- Create an Array Block with a nested array structure, e.g.,
[[1, 2], [3, 4], [5, 6]]
. - Add a Flatten Block and connect the Array Block to its
input
. - 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