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

179
Vistas
How to res convert to Like res2
 res = [{name:"sonu",roll:34,file:"asj.jpg", img_id:'1'},{name:"sonu",roll:34,file:"asj1.jpg", img_id:'2'},     {name:"sonu",roll:34,file:"asj2.jpg", img_id:'3'},{name:"dip",roll:67,file:"fgd3.jpg", img_id:'4'},     {name:"dip",roll:67,file:"fgd4.jpg", img_id:'5'},{name:"dip",roll:67,file:"fgd5.jpg", img_id:'6'}]

res convert to like res2

res2 = [{name:"sonu",roll:34, image: [{file:"asj.jpg",img_id:'1'},{file:"asj1.jpg", img_id:'2'},{file:"asj2.jpg", img_id:'3'}]},
{name:"dip",roll:67, image: [{file:"fgd3.jpg", img_id:'4'},{file:"fgd4.jpg", img_id:'5'},{file:"fgd5.jpg", img_id:'6'}]}]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try this

var groupBy = function (xs, key) {
  return xs.reduce(function (rv, x) {
    (rv[x[key]] = rv[x[key]] || []).push(x);
    return rv;
  }, {});
};

var res0= groupBy(res, 'name');

var res2 = [];
Object.keys(res0).forEach((item) => {
  
  var newObj = { name: item, roll: res0[item][0].roll, image: [] };

  res0[item].forEach((obj) => {
    newObj.image.push({ file: obj.file, img_id: obj.img_id });
  });

  res2.push(newObj);
});
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