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

150
Views
I have two arrays and I want to pair the array elements of the arrays which of sizes are not equal

This the code that i wrote

<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>

the output:

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

fault 4 and fault 5 remained unassinged to an assistant

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


i would like the jobs to be continuously assigned to a technician

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

0

As i said in the comment you need to restart index of assistant to start from the first value like:

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!