Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda