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

101
Views
Someone help me to convert from handwrited array to natural array

I have to convert that handwrited array, to natural array.

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

The array should looking like that: [ { '1': { id: 1, ocupped: 0 } } ], someone have an idea what i can do?

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

0

Actually, you should create the object first, then JSON.stringify it.

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!