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

85
Vistas
How can I group an array of objects in new array?

I have following array


    const arr = [
      {
       Images: [{ id: 1 }, { id: 2 }, { id: 3 }],
       MediaCategoryName: "Exterior",
       id: 51
      },

       {
       Images: [{ id: 7 }, { id: 8 }, { id: 9 }],
       MediaCategoryName: "Construction",
       id: 687
      },

      {
      Images: [{ id: 10 }, { id: 11 }, { id: 21 }],
      MediaCategoryName: "home",
      id: 755
     }
    ];

How can I create new array from them and put only Images ?

I need something like this

newArr = [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 7 }, { id: 8 }
         , { id: 9 }, { id: 10 }, { id: 11 }, { id: 21 }
         ]

Can someone help me to achieve this ?

Thanks :)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

using Array.prototype.flatMap()
It is just like doing a map to return images and then performing a flat afterwards

const arr = 
  [ { Images: [{ id:  1}, {id:  2}, {id:  3 }] , MediaCategoryName: 'Exterior',     id:  51 } 
  , { Images: [{ id:  7}, {id:  8}, {id:  9 }] , MediaCategoryName: 'Construction', id: 687 } 
  , { Images: [{ id: 10}, {id: 11}, {id: 21 }] , MediaCategoryName: 'home',         id: 755 } 
  ];


const res = arr.flatMap(({Images}) => Images)

console.log(JSON.stringify(res))
.as-console-wrapper {max-height: 100% !important;top: 0;}
.as-console-row::after {display: none !important;}

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try this code. It'll take each element from arr and takes

out = []
arr.forEach((el)=>{
    x.push(...el.Images)
})
about 4 years ago · Juan Pablo Isaza Denunciar
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