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

163
Views
¿Cómo puedo cambiar la matriz de objeto a objeto de matriz en javascript?

Estoy tratando de convertir una matriz de objetos en un objeto de matriz usando javascript.

Aquí está el código

 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", } ] } ]

Quiero crear este objeto:

 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", } ] }

Intenté resolverlo usando el método map in array pero no funcionó.

Alguien me puede ayudar por favor???

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

0

Este es un uso bastante sencillo de 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 Report

0

se puede resolver usando la función de map y Object.assign() y el operador de propagación

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