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

113
Vistas
Building a data structure to loop through nested children

Thanks for taking the time to read, I'm trying to work out a data structure that would be used for navigation in a react app, I do have control over the data to loop through. The potential amount of children is unknown, I can't find a good way to loop through all of the data in one function, if you could point me in the direction I'm sure I can learn from it or any help would be great! Also if would be easier to add items to the data structure that is an option!

const  data = {
  "nav": {
    "Nav Menu Title 1" : {
      "children": [
        {
          "name": "Sub Menu Title 1",
          "children" : [
            {
              "name": "Sub Sub Menu Title 1",
               "children" : [
                 {
                    "name": "Sub Sub Menu Option 1"

                  }
               ]
            },
            {
               "name" : "Sub Menu Option 1"
            }
          ]
        },
        {
          "name": "Option 1"
        },
        {
          "name": "Option 2"
        },
        {
          "name": "Option 3"
        },
        {
          "name": "Option 4"
        },
        {
          "name": "Option 5"
        }
      ]
    }
  }
}

for (let items in data.nav) {  
  let newNavItem = {
    id: 'apps.' + items,
    title: items,
    type: 'item',
    icon: 'heroicons-outline:shopping-cart'
  }
  
  if (data.nav[items].children.length > 0) {
    newNavItem.type = "collapse";
    newNavItem.children = [];
    // this is where I have trouble looping through children to add in a newNavItem
  }
}

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