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

169
Views
Convierta un objeto JSON en una matriz JSON basada en índice en JavaScript

Tengo un objeto JSON en el siguiente formato que quiero convertir en una matriz JSON. He intentado varias formas de lograr esto, pero no puedo tener éxito.

 { "name":{ "0":"mike", "1":"george", "2":"Andrew" }, "category":{ "0":"A", "1":"B", "2":"C" } }

La salida sería así:

 { "0":{ "name":"mike", "category":"A" }, "1":{ "name":"george", "category":"B" }, "2":{ "name":"andrew", "category":"C" } }

Soy nuevo en JSON. ¿Cómo puedo conseguir esto?

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

0

Puede hacer uso de Object.keys y Object.entries

 const obj = { name: { "0": "mike", "1": "george", "2": "Andrew", }, category: { "0": "A", "1": "B", "2": "C", }, }; const props = Object.keys(obj); const result = props.reduce((acc, key) => { Object.entries(obj[key]).forEach(([k, v]) => { if (!acc[k]) acc[k] = Object.fromEntries(props.map((p) => [p, ""])); acc[k][key] = v; }); return acc; }, {}); console.log(result);
 /* This is not a part of answer. It is just to give the output full height. So IGNORE IT */ .as-console-wrapper { max-height: 100% !important; top: 0; }

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!