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

236
Vistas
Key value pairs array into array object
pops = [
    [
      {
        key: 'test1',
        value: '0'
      }
    ],
    [
      {
        key: 'test2',
        value: '0'
      },
      {
        key: 'test3',
        value: '0'
      }
    ]
  ];

need to convert into this format

formated =
[{
 'test1':'0',
},
{
 'test2':'0',
 'test3':'0'
}]

I tried to solve the problem with this code but had no luck. can anyone help me to solve this problem? Thank you.

let formated = []
let count=0
for(let item of this.pops){
 
  for(let prop of item){
   formated[count].push(prop.key:prop.value)
  }
  count++;
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This can be achieved with a combination of map and reduce:

const pops = [
    [
      {
        key: 'test1',
        value: '0'
      }
    ],
    [
      {
        key: 'test2',
        value: '0'
      },
      {
        key: 'test3',
        value: '0'
      }
    ]
  ];
  
const formatted = pops.map(i =>  i.reduce( (acc,x) => ({...acc,[x.key]:x.value}),{}));

console.log(formatted);

over 4 years ago · Santiago Trujillo 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