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

164
Views
React Array to Object conversion

I am new to React and I am getting a response from json file as

methodTypes = ["BOTH","INSIDE","OUTSIDE"]
outputTypes = ["STANDARD","DETAILED","ALL_ATTRIBUTES_STANDARD","ALL_ATTRIBUTES_DETAILED"]

I want to convert it into below format using JavaScript.

methods = [
  {"methodKey":"BOTH","outputTypes":["STANDARD","DETAILED","ALL_ATTRIBUTES_STANDARD","ALL_ATTRIBUTES_DETAILED"]},
  {"methodKey":"INSIDE","outputTypes":["STANDARD","DETAILED","ALL_ATTRIBUTES_STANDARD","ALL_ATTRIBUTES_DETAILED"]},
  {"methodKey":"OUTSIDE","outputTypes":["STANDARD","DETAILED","ALL_ATTRIBUTES_STANDARD","ALL_ATTRIBUTES_DETAILED"]}
]

How can I achieve that? I tried using array.reduce method but, it is not working as expected.

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

0

Using Array#map:

const 
  methodTypes = ["BOTH","INSIDE","OUTSIDE"],
  outputTypes = ["STANDARD","DETAILED","ALL_ATTRIBUTES_STANDARD","ALL_ATTRIBUTES_DETAILED"];
  
const methods = methodTypes.map(methodKey => ({ methodKey, outputTypes: [...outputTypes] }));

console.log(methods);

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!