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

66
Vistas
Filtering Data using Properties values using ES6

Like to filter data based on properties values from Object Let's say I have an object:

{
  A: { value1: 4, value2: 2, value3: 5 },
  B: { value1: 2, value2: 5, value3: 8 },
  ...
}

I want to create object by filtering the object above so I have something like if I filter based on value1: 4 and value2: 2

{
  value1: 4,
  value2: 2,
  value3: 5
}

I am looking for a clean way to accomplish this using Es6.

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

0

const 
  obj = { A: { value1: 4, value2: 2, value3: 5 }, B: { value1: 2, value2: 5, value3: 8 } },
  filter = { value1: 4, value2: 2 };

// get key-value pairs of filter  
const filterPairs = Object.entries(filter);
  
// iterate over obj's values, and return the ones matching filterPairs
const matches = 
  Object.values(obj)
  .filter(o => filterPairs.every(([key, value]) => o[key] === value));
  
console.log(matches);

Note: if you only want to get the first matching object, use Array#find instead of Array#filter

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