flatten es-toolkit
Returns a new array that is flattened to the specified depth.
Usage
flatten(arr, depth = 1)
Use flatten when you want to flatten a nested array to a specific depth. It unwinds arrays within arrays to the specified level, creating a flatter structure.
It works identically to the Array#flat included in the JavaScript language, but it's faster.
You can control the depth to flatten only to the desired level.
Parameters
arrT[]required
The nested array to flatten.
depthDoptional
The depth to flatten. Defaults to 1.
Returns
Returns a new array flattened to the specified depth.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.