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

117
Views
How to convert an object with two arrays in an array of object?

I have two arrays like:

descriptionList: ["First", "Second", "Last"]

statusList: ["Jon", "Jim", "Den"]

I want to create a list of objects, like this:

  "subtasks": [
   {
     "description": First,
     "status": "Jon"
   },
   {
     "description": Second,
     "status": "Jim"
   },
  ....
],

Lists can have more than 3 elements.

What I have tried is this:

var result = {};
descriptionList.forEach((key, i) => result[key] = statusList[i]);
console.log('result', result);

What it prints is this one, which is not what I want:

{ First: "Jon", Second: "Jim", Last: "Den" }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can zip both arrays and use map to create the expected structure:

function zip(arr1, arr2) {
  return Array(Math.max(arr1.length, arr2.length)).fill(0).map((_, idx) => ([arr1[idx], arr2[idx]]));
}

const data = {
  descriptionList: ["First", "Second", "Last"],
  statusList: ["Jon", "Jim", "Den"]
};

const result = {
  subtasks: zip(...Object.values(data)).map(el => ({ description: el[0], status: el[1] }))
};

console.log(result);

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!