Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
¿Cómo combinar dos matrices en una matriz de objetos?

tengo dos listas

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

¿Cómo hacer una lista de este tipo? (una lista de objetos)

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

Intenté algo como esto, pero el resultado no es lo que esperaba:

 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 answers
Answer question

0

Solo necesita un bucle, no bucles anidados.

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

0

Puedes usar .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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!