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

64
Views
filter return combined matches
arr = [{name: "tom", tools:["spanner", "hammer", "screwdriver"]}, 
{name: "john", tools:["Mallet", "hammer", "screwdriver"]},
{name: "phil", tools:["Mallet", "Drill", "screwdriver"]}]


private filterObjectArray(arr: any, filterArr: any): any {
  return arr.filter((el: any) =>
    filterArr.some(
      (f: any) =>
        el.tools.toString()?.toLowerCase().indexOf(f.name?.toLowerCase()) >= 0
    )
  );
 }

My filter is similar to the above, at the moment if my filter returned filterArr = [{name: "screwdriver"}, {name: "hammer"}] then all objects would be returned as they all have at least one match in screwdriver.

However, how do I make it that only objects that has both filter properties display e.g. in the above I expect only the two objects tom and john return as they both have a screwdriver and hammer, whereas phil only has a screwdriver .

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

0

Here is a solution in JS. You can use every here to check if that every filter is included in the tools array

let arr = [{name: "tom", tools:["spanner", "hammer", "screwdriver"]}, 
{name: "john", tools:["Mallet", "hammer", "screwdriver"]},
{name: "phil", tools:["Mallet", "Drill", "screwdriver"]}]

let filterArr = [{name: "screwdriver"}, {name: "hammer"}]

let res = arr.filter(({tools}) => filterArr.every(({name}) => tools.includes(name)))

console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

You can use every instead of the includes(index >= 0)

It means

everything match then true otherwise false

private filterObjectArray(arr: any, filterArr: any): any {
    return arr.filter((el: any) => filterArr.every((f: any) => el.tools.includes(f.name)))
}
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!