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

169
Vistas
how to merge array to a multi array as key value pair
 var r = {},
 i,
    keys = ['one', 'two', 'three'],
    values = ['a', 'b', 'c'],['d', 'e',' f'];

for (let i = 0; i < keys.length; i++) {
    r[keys[i]] = values[i];
}

console.log(r);

Im just getting this error from my console. Uncaught SyntaxError: Invalid destructuring assignment target

This is the output i want to get.

{
  "one": "a",
  "two": "b",
  "three": "c"
},
{
  "one": "d",
  "two": "e",
  "three": "f"
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The main destructuring error occurs because you have an invalid values assignment, I added some square brackets around the two arrays to fix that.

let keys = ['one', 'two', 'three'],
 values = [['a', 'b', 'c'],['d', 'e',' f']];
    
let r = values.map(v => 
  Object.fromEntries(
    keys.map((k, i) => ([k, v[i]]))
  )
);

console.log(r);

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