Skip to content

feat: convert flat array objects into tree like data - #494

Open
hazrid93 wants to merge 1 commit into
sodiray:masterfrom
hazrid93:hazrid93/51_399
Open

feat: convert flat array objects into tree like data#494
hazrid93 wants to merge 1 commit into
sodiray:masterfrom
hazrid93:hazrid93/51_399

Conversation

@hazrid93

Copy link
Copy Markdown

Closes #399.

Add listToTree(items, {idKey='id', parentKey='parent', childrenKey='children'}) that returns the root nodes of a tree: each item is cloned with an empty children array (inputs are not mutated), children are attached to their parent by id, and items whose parent reference is missing/null or points to a non existent node become roots. Preserves input order within children lists. Supports custom key names and numeric/string ids.

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

@hazrid93 is attempting to deploy a commit to the rayunishinedev's projects Team on Vercel.

A member of the Team first needs to authorize it.

Closes sodiray#399.

Add listToTree(items, {idKey='id', parentKey='parent', childrenKey='children'}) that returns the root nodes of a tree: each item is cloned with an empty children array (inputs are not mutated), children are attached to their parent by id, and items whose parent reference is missing/null or points to a non existent node become roots. Preserves input order within children lists. Supports custom key names and numeric/string ids.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Convert flat array objects to tree-like data

1 participant