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

134
Visualizações
Javascript filter object by condition on only one of its keys

I have an object with the following structure:

data = 
{
  columns: array of objects,
  rows: [
    {
      id: 1,
      process: "A",
      status: "ok"
    },
    {
      id: 2,
      process: "A",
      status: "ko"
    },
    {
      id: 3,
      process: "B",
      status: "ok"
    },
    ...
  ]
}

I then want to create another object that has the same column values, but in the rows field I want to put only the objects that have process === "A".

I've come up with this so far, that I think it's fine:

const filteredData = {
    "columns": data.columns,
    "rows": selectedProcess !== '' ? data.rows.filter(r => r.process === selectedProcess) : []
  }

My question is if there is another way to make this in a more clever way.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can check out the solution Below:

const filteredData = {
    "columns": data.columns,
    "rows": data.rows.filter(item=>item.process==='A')
  }

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