Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda