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

156
Vistas
how can i change array of object to object of array in javascript?

I am trying to convert array of objects to object of array using javascript.

Here is the code

const data = [
{
  items: [
    {
      code: "location_list_page",
      icon: "environment",
      id: 1,
      link: "/configurations/locations",
      name: "Localisations",
    }
  ]
},
{
  items: [
    {
      code: "service_list_page",
      icon: "api",
      id: 5,
      link: "/configurations/services",
      name: "Services",
    }
  ]
 }
]

I want to create this object:

const data = {
  items: [
    {
      code: "location_list_page",
      icon: "environment",
      id: 1,
      link: "/configurations/locations",
      name: "Localisations",
    },
    {
      code: "service_list_page",
      icon: "api",
      id: 5,
      link: "/configurations/services",
      name: "Services",
    }
  ]
}

I try to solve it using map in array method but it didn't work.

Anyone can help me please ???

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is a pretty straightforward use of flatMap:

const data = [
{
  items: [
    {
      code: "location_list_page",
      icon: "environment",
      id: 1,
      link: "/configurations/locations",
      name: "Localisations",
    }
  ]
},
{
  items: [
    {
      code: "service_list_page",
      icon: "api",
      id: 5,
      link: "/configurations/services",
      name: "Services",
    }
  ]
 }
]

const result = {items: data.flatMap(x => x.items)};

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

it can be solved using map function and Object.assign() and the spread operator

var new_data = {"items": data.map(x=> Object.assign({}, ...x["items"]))};
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