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

116
Vistas
Filter inside a array of dicts by key

I have that array of dict:

       arrayDict: [
        {
          Description: "Dict 0"
          Category: [
            'First',
            'Both',
          ],
        },
        {
          Description: "Dict 1",
          Category: [
            'Second',
            'Both',
          ],
        },
      ]

i would like to filter inside that array by Category. i will recieve a category and i need to filter. If i recieve "Both", i need to return "Dict 1" and "Dict 0". if i receive "Second", i return only "Dict 1".

How can i do that?

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

0

You can achieve your goal by using filter method, like this:

const  arrayDict = [
        {
          Description: "Dict 0",
          Category: [
            'First',
            'Both',
          ],
        },
        {
          Description: "Dict 1",
          Category: [
            'Second',
            'Both',
          ],
        },
      ];
      
const filterDict = (key)=> arrayDict.filter(({Category}) => Category.includes(key))

console.log('First:',filterDict('First'));
console.log('Second:',filterDict('Second'));
console.log('Both:',filterDict('Both'));

about 4 years ago · Juan Pablo Isaza Denunciar

0

somthing like this:

arrayDict.filter((item)=> item.Category.includes('Both'))
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can simply use the filter() : higher order function provided by JS.

var arrayDict = [
    {
      Description: "Dict 0",
      Category : [
        'First',
        'Both',
      ]
    },
    {
      Description: "Dict 1",
      Category : [
        'Second',
        'Both',
      ],
    },
  ]

  let input = 'Both';
  let filteredData = arrayDict.filter((elm) => {
    return elm.Category.includes(input)
})

console.log(filteredData);
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