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

108
Views
javascript how to filter array for multiple condition

This is the filter:

var filter = {
  address: ['England'],
  name: ['Mark', 'Tom'] // Mark or Tom in this case
};
var users = [{
    name: 'John',
    email: 'johnson@mail.com',
    age: 25,
    address: 'USA'
  },
  {
    name: 'Tom',
    email: 'tom@mail.com',
    age: 35,
    address: 'England'
  },
  {
    name: 'Mark',
    email: 'mark@mail.com',
    age: 28,
    address: 'England'
  }
];

The filtered result should be

  {
    name: 'Tom',
    email: 'tom@mail.com',
    age: 35,
    address: 'England'
  },
  {
    name: 'Mark',
    email: 'mark@mail.com',
    age: 28,
    address: 'England'
  }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You take your users, filter it, and see if the name is contained in the filters.

const onlyMarkAndTom = users.filter(user => filter.name.includes(user.name))

Include additional conditions to narrow down the result

const onlyMarkAndTom = users.filter(user => filter.name.includes(user.name) && ...)
about 4 years ago · Juan Pablo Isaza Report

0

users.filter((user) => {
  if (!filter.address.includes(user.address)) {
    return false;
  }
  if (!filter.name.includes(user.name)) {
    return false;
  }
  return true;
});
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!