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

121
Vistas
How to convert an object with two arrays in an array of object?

I have two arrays like:

descriptionList: ["First", "Second", "Last"]

statusList: ["Jon", "Jim", "Den"]

I want to create a list of objects, like this:

  "subtasks": [
   {
     "description": First,
     "status": "Jon"
   },
   {
     "description": Second,
     "status": "Jim"
   },
  ....
],

Lists can have more than 3 elements.

What I have tried is this:

var result = {};
descriptionList.forEach((key, i) => result[key] = statusList[i]);
console.log('result', result);

What it prints is this one, which is not what I want:

{ First: "Jon", Second: "Jim", Last: "Den" }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can zip both arrays and use map to create the expected structure:

function zip(arr1, arr2) {
  return Array(Math.max(arr1.length, arr2.length)).fill(0).map((_, idx) => ([arr1[idx], arr2[idx]]));
}

const data = {
  descriptionList: ["First", "Second", "Last"],
  statusList: ["Jon", "Jim", "Den"]
};

const result = {
  subtasks: zip(...Object.values(data)).map(el => ({ description: el[0], status: el[1] }))
};

console.log(result);

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