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

134
Views
How to create an array of object with 2 arrays .js

I have two arrays

study_id: ["1", "2", "3"],
study_name: ["clinic Study", "study test", "test 2"],

I want to create an array of objects with the array as follows:

  "studies": [{
      "study_id": "1",
      "study_name": "clinic study"
    },
    {
      "study_id": "2",
      "study_name": "test study"
    }
  ]

How to achieve this? thanks

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

0

there are a few ways to do this but one ES6 solution is to use map method in first array and map each element to a object which key is element from first array and value is element with same index in the second array.

var a = [1, 2, 3]
var b = ['a', 'b', 'c']

var c = a.map((e, i) => {
  return { [e]: b[i] };
});

console.log(c)

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!