Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report

0

somthing like this:

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!