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

93
Views
¿Cómo puedo agrupar una matriz de objetos en una nueva matriz?

tengo la siguiente matriz

 const arr = [ { Images: [{ id: 1 }, { id: 2 }, { id: 3 }], MediaCategoryName: "Exterior", id: 51 }, { Images: [{ id: 7 }, { id: 8 }, { id: 9 }], MediaCategoryName: "Construction", id: 687 }, { Images: [{ id: 10 }, { id: 11 }, { id: 21 }], MediaCategoryName: "home", id: 755 } ];

¿Cómo puedo crear una nueva matriz a partir de ellos y poner solo Images ?

necesito algo como esto

 newArr = [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 7 }, { id: 8 } , { id: 9 }, { id: 10 }, { id: 11 }, { id: 21 } ]

¿Puede alguien ayudarme a lograr esto?

Gracias :)

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

0

usando Array.prototype.flatMap()
Es como hacer un mapa para devolver imágenes y luego realizar un plano después.

 const arr = [ { Images: [{ id: 1}, {id: 2}, {id: 3 }] , MediaCategoryName: 'Exterior', id: 51 } , { Images: [{ id: 7}, {id: 8}, {id: 9 }] , MediaCategoryName: 'Construction', id: 687 } , { Images: [{ id: 10}, {id: 11}, {id: 21 }] , MediaCategoryName: 'home', id: 755 } ]; const res = arr.flatMap(({Images}) => Images) console.log(JSON.stringify(res))
 .as-console-wrapper {max-height: 100% !important;top: 0;} .as-console-row::after {display: none !important;}

about 4 years ago · Juan Pablo Isaza Report

0

Puedes probar este código. Tomará cada elemento de arr y toma

 out = [] arr.forEach((el)=>{ x.push(...el.Images) })
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!