Aller au contenu principal

flatten()

flatten<T>(node): T[]

Flattens a composite tree into an array of all node data. Traverses depth-first, pre-order (parent before children).


Type Parameters

T: T

The data type


Parameters

node: Composite<T>

The root node to flatten


Returns: T[]

Array of all node data


Since

2.4.0


Example

const allFiles = flatten(tree);
// [{ name: "root", ... }, { name: "file1.txt", ... }, ...]