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

116
Views
Parent value as average of all children within nested object

I have a deeply nested object with children. Every parent has a key of average. The average should be the average of all the total_value from all its children and subchildren. How can I make this work?

At the moment I'm only able to loop the whole object using a recursive function

_.each(data, function(parent) { 
    if(parent.__children.length > 0) { 
        ....
    }
});

const data = [{
   category: "name-1"
   average: 0,
   __children: [
      {
           category: "name-1.1",
           average: 0
           total_value: 5,
           __children: [{
                category: "name-2.1",
                average: 0
                total_value: 2,
                __children: []
           }]
      }, {
           category: "name-1.2",
           total_average: 0,
           total_value: 10,
           __children: [{
                category: "name-2.2",
                average: 0
                total_value: 2,
                __children: []               
           }]
      } 
  ]
}];
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!