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

90
Vistas
I want to transform all the data in my JavaScript nested array having the same name and then group them together

I'm trying to group the data in my nested array that has same categoryName together, then transform them into an object. The code snippet below shows what my data looks like. .......................................................................................................................................................................................................

here is what the data looks like

data = [
    {
        name: "listName",
        id:434343,
        data: [
            {
                id:434343,
                categoryName: school, 

            }, 
            {
                id:234343,
                categoryName: house, 
                
            },
            {
                id:2000,
                categoryName: school, 
                
            },
            {
                id:2333,
                categoryName: house, 
                
            }
        ]
    }, 
    {
        name: "anotherListName",
        id:434343,
        data: [
            {
                id:434343,
                categoryName: school, 

            }, 
            {
                id:234343,
                categoryName: house, 
                
            },
            {
                id:2000,
                categoryName: school, 
                
            },
            {
                id:2333,
                categoryName: house, 
                
            }
        ]
    }
]

This is what the transformed data should look like

transformed = [
    {
        name: "listName",
        id:43453,
        data: {
            school: [
               {
                id:434343,
                categoryName:school   
               }, 
               {
                id:2000,
                categoryName:school   
               }, 
            ],
            house: [
               {
                id:234343,
                categoryName:house   
               }, 
               {
                id:2333,
                categoryName:house   
               }, 
            ],
        } 
    },
    {
        name: "listName",
        id:43453,
        data: {
            school: [
               {
                id:434343,
                categoryName:school   
               }, 
               {
                id:2000,
                categoryName:school   
               }, 
            ],
            house: [
               {
                id:234343,
                categoryName:house   
               }, 
               {
                id:2333,
                categoryName:house   
               }, 
            ],
        } 
    },
]

this is my code

const transformed = []
list.forEach(d => {
    d.data.forEach(item => {
        const exist = transformed.find(t => t.categoryName == item.name)
        if(exist) 
           ///got confused at this point
        else 
            transformed.push(item)
    })
})
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