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

154
Views
How to remove objects from root of array if a duplicated is found in a Children object

The current code works with no problem. I like to know if there is a cleaner or better way to remove objects from the root of my array if a value is found somewhere in a nested object. I want to remove the object

const baseArray = [
    {
        title: 'Test folder',
        UUID: '54F5E250-1C5F-49CC-A963-5B7FD8884E48',
        Children: [
          {
            title: 'nothing',
            UUID: 123,
          },
        ]
      },
      {
        title: 'nothing',
        UUID: 123,
      },
    ]

  const currArray = baseArray

  const removeRootUUID = (baseArray, currArray) => {
    const delInRoot = uuidRef => {
      baseArray.forEach((obj, i) => {
        if (obj.UUID === uuidRef) {
          baseArray.splice(i, 1);
        }
      });
    };
    for (const obj of currArray) {
      if (obj.Children) {
        obj.Children.forEach(node => {
          delInRoot(node.UUID);
        });
        removeRootUUID(baseArray, obj.Children);
      }
    }
  };

output I am looking for is below. (because UUID is founded in root and in another nested object)

{
        title: 'Test folder',
        UUID: '54F5E250-1C5F-49CC-A963-5B7FD8884E48',
        Children: [
          {
            title: 'nothing',
            UUID: 123,
          },
        ],
      }
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!