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

109
Views
How to reduce array of object by specific property

Let's say we have following array of objects:

const arrOfObjects = [
  {
    name: "A",
    color: "red",
    id: 1,
  },
  {
    name: "B",
    color: "blue",
    id: 2,
  },
  {
    name: "C",
    color: "green",
    id: 3,
  },
  {
    name: "A",
    color: "red",
    id: 1,
  },
  {
    name: "A",
    color: "red",
    id: 1,
  },
  {
    name: "A",
    color: "red",
    id: 1,
  },
  {
    name: "C",
    color: "green",
    id: 3,
  },
];

I would like to reduce this array of objects by property ID and add to this object property quantity which gives information how many identical object exist in this array.

Expect result:

const reduced = [
  {
    name: "A",
    color: "red",
    id: 1,
    quntitiy: 4,
  },
  {
    name: "C",
    color: "green",
    id: 3,
    quntitiy: 2,
  },
  {
    name: "B",
    color: "blue",
    id: 2,
    quntitiy: 1,
  },
];

I am sure, I need to use reduce method.

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!