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

263
Views
Array of objects --> sum of each groups and insert at the end of the group

I want to group the array by a specific key and display its sum at the end of each group.

Example:

var array = [
  { name: "Naruto", qty: 5 },
  { name: "Sasuke", qty: 2 },
  { name: "Naruto", qty: 2 },
  { name: "Hinata", qty: 4 },
  { name: "Sasuke", qty: 4 },
]

Expected Result:

[
// naruto's group
  { name: "Naruto", qty: 5 },
  { name: "Naruto", qty: 2 },
  { name: "Total", qty: 7 },

// sasuke's group
  { name: "Sasuke", qty: 2 },
  { name: "Sasuke", qty: 4 },
  { name: "Total", qty: 6 },

// hinata's group
  { name: "Hinata", qty: 4 },
  { name: "Total", qty: 4 },

]
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!