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

142
Vistas
How to combine two arrays into an array of objects?

I have two lists,

l1= ["apple","banana","grape"]
l2 = ["red","yellow","black"]

How to make a list of this type? (a list of objects)

l3 = [
   {fruit:"apple",colour:"red"},
   {fruit:"banana",colour:"yellow"},
   {fruit:"grape",colour:"balack"}
]

I tried something like this, but the output is not what I expected:

let l3 = [];
let Obj = {};
for (let l = 0;l<l1.length;l++) {
    Obj = {};
    for (h=0;h<l2.length;h++) {
        Obj["fruit"] = l1[h];
        Obj["colour"] = l2[h];
    }
    l3.push(Obj);
}
return l3;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You only need one loop, not nested loops.

for (let i = 0; i < l1.length; i++) {
    l3.push({fruit: l1[i], colour: l2[i]});
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use .map.

const l1 = ["apple", "banana", "grape"];
const l2 = ["red", "yellow", "black"];
const l3 = l1.map((fruit, index) => ({ fruit, color: l2[index] }));

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