flatten

array

Flattens nested arrays into a single-level array

Syntax

flatten(array)

Parameters

array (array)

The nested array to flatten

Returns

array

A flattened single-level array

Examples

Input:
[[1, 2], [3, 4]] | flatten
Output:
[1, 2, 3, 4]
Input:
[1, [2, [3, 4]]] | flatten
Output:
[1, 2, 3, 4]

The flatten() function recursively flattens nested arrays into a single-level array, combining all elements regardless of nesting depth.

Usage

Use flatten() when working with nested data structures that need to be converted to a simple list, or when combining results from multiple array operations.

Related Functions