Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda