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

143
Views
filter array based on multiple condition

I would like to get the result of my event based on the filter.

const filter = [
  { type: 'type', value: ['In Person'] },
  { type: 'city', value: ['Boston', 'Miami', 'New York'] },
];

const events = [
  { node: { city: 'Boston', type: 'In Person', name: 'Boston Party' } },
  { node: { city: 'New Jersey', type: 'In Person', name: 'Hello Cookie' } },
  { node: { city: 'Boston', type: 'Virtual', name: 'Sales Kick Off' } },
];

const result = events.filter(o => Object
  .entries(o.node)
  .every(([k, v]) => filter
    .some(({ type, value }) => type === k && value.includes(v)),),)

console.log(result)

I want the first object of my events because filter contain Boston and In Person. (This function will work if I remove the key name on my events). How this function can return a result if i have more key and value on my events.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could filter with filter.

const
    filter = [{ type: 'type', value: ['In Person', 'Virtual'] }, { type: 'city', value: ['Boston', 'Miami', 'New York'] }],
    events = [{ node: { city: 'Boston', type: 'In Person', name: 'Boston Party' } }, { node: { city: 'New Jersey', type: 'In Person', name: 'Hello Cookie' } }, { node: { city: 'Boston', type: 'Virtual', name: 'Sales Kick Off' } }],
    result = events.filter(({ node }) =>
        filter.every(({ type, value }) => !value.length || value.includes(node[type]))
    );

console.log(result)
.as-console-wrapper { max-height: 100% !important; top: 0; }

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!