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

133
Vistas
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 Respuestas
Responde la pregunta

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