Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Transform a list of projects to tree structure of projects and sub-projects

Here are some dummy projects related to each other by parentId, the top level projects have a parentId of 0

const projects = [
  {id:4, parentId:1, name:'pro 4', children: []},
  {id:5, parentId:1, name:'pro 5', children: []},
  {id:6, parentId:2, name:'pro 6', children: []},
  {id:7, parentId:4, name:'pro 7', children: []},
  {id:10, parentId:9, name:'pro 10', children: []},
  {id:8, parentId:4, name:'pro 8', children: []},
  {id:9, parentId:7, name:'pro 9', children: []},
  {id:1, parentId:0, name:'pro 1', children: []},
  {id:2, parentId:0, name:'pro 2', children: []},
  {id:3, parentId:0, name:'pro 3', children: []},
  {id:11, parentId:10, name:'pro 11', children: []},
];

These projects need to be structured in tree form like this:

const tree = {
  project.children: [
    sub-project.children: [{},{},{},{},{}],
    sub-project.children: [
      sub-project.children: [{},{},{}],
    ]
  ]
};

I need to solve this problem with a recursive function as the level of sub-projects is limitless

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!