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

135
Views
Combine one array's values based on duplicate dates

I am trying to solve this and keep getting stuck. I am currently trying to do this with lodash but open to any solution:

EDIT: I've done many searches and the suggested links are not the desired output

Array structure:

[
    { "date": "2022-03-01", "A": 11549 },
    { "date": "2022-03-01", "B": 4536 }
]

to become

[
    { "date": "2022-03-01", "A": 11549, "B": 4536 },
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Would this work for you ?

const arr = [
  { date: '2022-03-01', A: 11549 },
  { date: '2022-03-01', B: 4536 },
  { date: '2022-03-01', C: 8000 },
  { date: '2022-03-01', D: 4000, F: 7500 },
  { date: '2022-04-02', A: 4536 },
];

const r = Object.values(arr.reduce((o, curr) => {
  if (o[curr.date]) {
    for (const entry of Object.entries(curr)) o[curr.date][entry[0]] = entry[1];
  } else o[curr.date] = curr;
  return o;
}, {}))

console.log(r);

about 4 years ago · Juan Pablo Isaza Report
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!