For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/flattenDeep.md.

flattenDeep es-toolkit

Returns a new array with all depths of a nested array flattened.

const result = flattenDeep(arr);

Usage

flattenDeep(arr)

Use flattenDeep when you want to completely flatten a nested array, no matter how deeply nested it is. It unwinds all nested arrays within the array, creating a single flat structure.

It works identically to calling Array#flat as flat(Infinity) in the JavaScript language, but it's faster.

import { flattenDeep } from 'es-toolkit/array';

// Flatten all nested levels
const array = [1, [2, [3]], [4, [5, 6]]];
const result = flattenDeep(array);
// Returns: [1, 2, 3, 4, 5, 6]

It completely flattens even highly complex nested structures.

import { flattenDeep } from 'es-toolkit/array';

const complexArray = [1, [2, [3, [4, [5]]]], 6];
const result = flattenDeep(complexArray);
// Returns: [1, 2, 3, 4, 5, 6]

Parameters

arrT[]required

The nested array to flatten.

Returns

Returns a new array with all depths flattened.

Array<ExtractNestedArrayType<T>>
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.