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

155
Views
Tengo dos matrices y quiero emparejar los elementos de matriz de las matrices cuyos tamaños no son iguales

Este es el código que escribí

 <script> var jobs = ['fault 1','fault 2','fault 3','fault 4','fault 5']; var assistant =['John :','Martin :','lovemore :']; var langKeys = {}; for (var i = 0; i < jobs.length; i++) { var job = jobs[i]; langKeys[job] = assistant[i]; } console.log(JSON.stringify(langKeys)); </script>

La salida:

 {"fault 1":"John :","fault 2":"Martin :","fault 3":"lovemore :"}

la falla 4 y la falla 5 quedaron sin asignar a un asistente

 the desired output {"fault 1":"John :","fault 2":"Martin :","fault 3":"lovemore :","fault 4":"John :","fault 5":"Martin:"}

me gustaria que los trabajos fueran asignados continuamente a un tecnico

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como dije en el comentario, debe reiniciar index del assistant para comenzar desde el primer valor como:

 const jobs = ['fault 1', 'fault 2', 'fault 3', 'fault 4', 'fault 5']; const assistant = ['John :', 'Martin :', 'lovemore :']; const assistantLenght = assistant.length; let assistantIndex = 0; const langKeys = {}; for (var i = 0; i < jobs.length; i++) { var job = jobs[i]; langKeys[job] = assistant[assistantIndex]; assistantIndex++ if (assistantIndex >= assistantLenght) { assistantIndex = 0; } } console.log(JSON.stringify(langKeys));

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!