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

201
Views
How to tree a array as hierarchy without to know the level limit

I have a list template like this

list = [
    {
      id: "G1",
      text: "Group 1",
      idparent: "",
      children: [
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "1",
          text: "Task 1"
          idparent: "G1",
        },
        {
          start: "2014-10-03",
          end: "2014-10-05",
          id: "2",
          text: "Task 2"
          idparent: "G1",
        }    
      ]
    },
    {
      start: "2014-10-01",
      end: "2014-10-03",
      id: "3",
      text: "Task 3"
      idparent: "",
    },    
  ];

The first item with children is a group of items and the last one is a single item. And the list to be treated is the following

list_to_tree = [
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "G1",
          text: "Group 1"
          id_parent: ""
        },   
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "1",
          text: "Task 1"
          id_parent: "G1"
        },   
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "2",
          text: "Task 2",
          id_parent: "G1"
        },   
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "3",
          text: "Task 3"
          id_parent: ""
        },   
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "G2",
          text: "Group 2"
          id_parent: "G1"
        },
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "4",
          text: "Task 4",
          id_parent: "G2"
        },
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "5",
          text: "Task 5",
          id_parent: ""
        },
        {
          start: "2014-10-01",
          end: "2014-10-03",
          id: "G3",
          text: "Group 3",
          id_parent: ""
        },
   ];

How to sort this list so that it can look like the model above knowing that we can have an infinite number(n) of child spots (group or item). Eg: Task -> subtasks -> n(substasks) if have

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!