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

201
Views
How to convert an array of indexed objects to a plain object

How to convert an array of this type:

place:
[
     {
         "_id": "xxxxx",
         "loc": [
             0: "xxx",
             1: "xxx"
         ]
     }
]

To something like this:

place:
{
  lat: "xxx"
  lng: "xxx"
  _id: "xxxxx"
}

Using javascript, I tried something like

let object = {};

place.forEach(element => {
     object[element[0]] = element[1];
});

but it did not work for me, I am using angular to make a method and I need to convert the array of objects that I am showing

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

0

Assuming the totally invalid

"loc": [
    0: "xxx",
    1: "xxx"
]

is actually just

"loc": [
    "xxx",
    "xxx"
]

let place =
[
     {
         "_id": "xxxxx",
         "loc": [
             "xxx",
             "xxx"
         ]
     }
]

let { _id, loc: [lat, lng]} = place[0];
let output = { _id, lat, lng};
console.log(output);

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!