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

93
Views
Alguien que me ayude a convertir de matriz escrita a mano a matriz natural

Tengo que convertir esa matriz escrita a mano en una matriz natural.

 var json = "["; if(result.length > 0) { json += `{ "${result[0].ped_id}": { "id": ${result[0].id}, "ocupped": ${result[0].ocupped} } }`; } json += "]";

La matriz debería verse así: [ { '1': { id: 1, ocupped: 0 } } ] , ¿alguien tiene una idea de lo que puedo hacer?

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

0

En realidad, primero debe crear el objeto, luego JSON.stringificarlo.

 let result = [{ ped_id: 101, occuped: "something" }] let json = []; if (result.length > 0) { json.push({ [result[0].ped_id]: { id: result[0].ped_id.toString(), ocupped: result[0].ocupped } }) } json = JSON.stringify(json) console.log(json)

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!