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

267
Views
How to remove duplicate elements from an array of objects JS

I have array objects with keys path and current. How to remove duplicate elements, where key current has the same value.

let arrPath = [{
  path: [1, 2],
  current: "K"
}, {
  path: [0, 3],
  current: "I"
}, {
  path: [1, 3],
  current: "N"
}, {
  path: [1, 4],
  current: "N"
}, {
  path: [0, 2],
  current: "G"
}, {
  path: [2, 2],
  current: "G"
} ];

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can remove duplicate objects (duplicate object in the sense that it contains duplicate current property) by using reduce.

let arrPath = [{ path: [1, 2], current: "K" }, { path: [0, 3], current: "I" }, { path: [1, 3], current: "N" }, { path: [1, 4], current: "N" }, { path: [0, 2], current: "G" }, { path: [2, 2], current: "G" }]

let resultData = arrPath.reduce((elements, obj, index) => {
  let existingData = elements.find(element =>
    element.current === obj.current
  );
  if (!existingData) {
    elements.push(obj);
  }
  return elements;
}, []);

console.log(resultData)

about 4 years ago · Santiago Trujillo Report

0

You can map each value in the array to an entry using the current values for the keys.

Then use these entries to construct a Map object, effectively eliminating duplicate entries.

You can convert the Map back to an array using Array.from

Array.from(new Map(arrPath.map(o => [o.current, o])).values())
about 4 years ago · Santiago Trujillo 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!