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

121
Vistas
How to filter and separate nested objects

I am trying to get the objects that have the similar value. I am trying with this but I am not getting the objects with similar values:

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' ...},
    ]
  }
];

I want obtain this:

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' ...}
   ]
  }
]

any suggestion?

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

0

Try below code

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 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