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

277
Views
Remove duplicates in nested objects of object

Trying to parse some network descriptions from devices, hitting a problem where a description could be duplicate across types. This causes errors further down the road in code. What is the best choice with lodash or javascript to compare each nested object and remove duplicates until they don't exist in the arrays. The goal is that string 1 - 111 would be removed until it only exists in one object.

const data = {
    "hostname": {
        "typeA": [
            "string 1 - 111",
            "string 2 - 222",
            "string 3 - 333"
        ],
        "typeB": [
            "string 1 - 111",
            "string 4 - 444",
            "string 5 - 555"
        ],
        "typeC": [
            "string 1 - 111",
            "string 6 - 666"
        ]
    }
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You simply need to iterate over each type array and filter based on a Set of previously seen values. Here mutating data in place using filter() to both populate the Set and to return the filtered array.

const data = {
  hostname: {
    typeA: ['string 1 - 111', 'string 2 - 222', 'string 3 - 333'],
    typeB: ['string 1 - 111', 'string 4 - 444', 'string 5 - 555'],
    typeC: ['string 1 - 111', 'string 6 - 666'],
  },
};

const seen = new Set();

for (const key of Object.keys(data.hostname)) {
  data.hostname[key] = data.hostname[key].filter((s) => {
    const _seen = seen.has(s);
    seen.add(s);

    return !_seen;
  });
}

console.log(data);

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!