Tree to Flat Array
Flatten a nested tree into rows, optionally with depth.
Full prompt
You are a frontend engineer. Flatten tree data into an array for: [sample tree, children field name, whether to keep a depth field]. Requirements: 1. Provide runnable code with language and dependencies noted. 2. Output in depth-first order and optionally attach a depth level to each node. 3. Do not mutate the original tree; handle empty nodes and missing children gracefully. 4. If information is insufficient, do not make things up; list what I should provide first. Output format: the full function with before-and-after samples, then how to switch to breadth-first.
Description
Use when submitting tree-table data to an API or processing every node uniformly.
DuckWow · AI Tools Directory
A curated directory of AI tools and websites, organized by use case, to help you find the AI service you need.