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

127
Views
Cómo filtrar y separar objetos anidados

Estoy tratando de obtener los objetos que tienen un valor similar. Estoy intentando con esto pero no obtengo los objetos con valores similares:

 const dataWork = [ { _id:1, firstName:'Leo', lastName:'Bla', mail:'leo.bla@gmail.com', certifications:[ {_id:1, certification:'C1 Certification'}, {_id:2, certification:'C3 Certification'} ], education:[ {_id:1, school:'School A'} ], work:[ {_id:1, company:'Company A', industry:'Industry A' ...}, {_id:2, company:'Company B', industry:'Industry B' ...}, {_id:3, company:'Company A', industry:'Industry A' ...}, {_id:4, company:'Company C', industry:'Industry C' ...}, {_id:5, company:'Company C', industry:'Industry C' ...}, {_id:6, company:'Company B', industry:'Industry A' ...}, {_id:7, company:'Company D', industry:'Industry B' ...}, ] } ];

Quiero obtener esto:

 result = [ { industryA:[ {_id:1, company:'Company A' ...}, {_id:3, company:'Company A' ...}, {_id:6, company:'Company A' ...} ], industryB:[ {_id:2, company:'Company B' ...}, {_id:7, company:'Company B' ...} ], industryC:[ {_id:4, company:'Company C' ...}, {_id:5, company:'Company C' ...} ] } ]

¿cualquier sugerencia?

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

0

Pruebe el siguiente código

 const data = { work:[ {_id:1, company:'Company A', industry:'Industry A'}, {_id:2, company:'Company B', industry:'Industry B'}, {_id:3, company:'Company A', industry:'Industry A'}, {_id:4, company:'Company C', industry:'Industry C'}, {_id:5, company:'Company C', industry:'Industry C'}, {_id:6, company:'Company B', industry:'Industry A'}, {_id:7, company:'Company D', industry:'Industry B'} ]} const obj = {}; data.work.map(el => { obj[el.industry] = obj[el.industry] ? [...obj[el.industry], el] : [el]; }) console.log(obj);

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!