Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda