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

131
Views
Cómo combinar 2 matrices de manera que el primer elemento de la matriz1 y el primer elemento de la matriz2 y así sucesivamente formen una nueva matriz

Tengo 2 matrices. El primero contiene los años como [2021,2020,2019,2018,2017] y el segundo contiene el número de ocurrencias como [2,3,1,3,3] Quiero que la nueva matriz se vea así [[2021,2],[2020,3],[2019,1],[2018,3],[2017,3]] ¿Cómo hacer esto? ¡Por favor ayuda! Gracias de antemano.

ACTUALIZAR:

 const merge = (y, o) => { const res = []; y.forEach((year, i) => res.push(`${year},${o[i]}`) ); return res; }; console.log(merge(allyears,farray))

Intenté hacer esto y funciona bien, pero la nueva matriz se ve así

 ["2021,3","2020,1","2019,2","2018,3","2017,3"]

Cómo hacer que se vea de esta manera

 [[2021,2],[2020,3],[2019,1],[2018,3],[2017,3]]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Asegúrese de que la longitud de 2 matrices sea igual

Entonces tenemos:

 const arr1 = [2021,2020,2019,2018,2017]; const arr2 = [2,3,1,3,3]; const combine = arr1.map((value, index) => ([value, arr2[index]])) console.log(combine)

P/s: Hay algunas otras soluciones que puede usar, pero solo la anterior

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!