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

227
Views
compare two arrays and remove duplicates

code

let arr = [{service:"test", program:[{pg:123, ag:123}]},
           {service:"test", program:[{pg:123, ag:123}]},
           {service:"test1", program:[{pg:1234, ag:1234}]}]
           
const result = arr.reduce((unique, o) => {
          if (!unique.some(obj => obj.service === o.service)) {
            unique.push(o);
          }
          return unique;
        }, []);

console.log(result)

Here I am trying to compare the array of objects and remove duplicates but I was able to compare only first level of array of object. I need to compare the "programs" array of objects as well.

Expected Output

[{service:"test", program:[{pg:123, ag:123}]},
 {service:"test1", program:[{pg:1234, ag:1234}]}]
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!