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

355
Views
How to filter json data with multiple includes values

Includes method working for only one Value but i want to filter multiple values with comma like this "mahmoud, faizan" i'll get these value from user input

json Data

[{
    
    "text": "adnan hassan"
}, {
    
    "text": "adnan hassan mahmoud",
}, {
    
    "text": "adnan hassan faizan",
}]

Filter Function

const filterFunction = (a) => {
   if(includeKeyword)
     return a.text.includes("mahmoud")
    }
  

Filter Function with map render

postRes.filter(filterFunction).map((data, index) => (
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I gave you two return statements to choose from, depending on if you want to match all parts or at least one part out of what was typed in:

const filterFunction = (a) => {
   if(includeKeyword)
     const parts = userInput.split(",");
     // if you need the returned element to match *all* parts (AND)
     return parts.every(p => a.text.includes(p.trim());

     // if you need it to match *at least one* part (OR)
     return parts.some(p => a.text.includes(p.trim());
   }
};
about 4 years ago · Juan Pablo Isaza Report

0

for your senario you can customize the filter function to get a second parameter and use array.some:

const filterFunction = (a, searchArray) => {
  if (searchArray.some((v) => a.text.includes(v))) {
   return a;
    }
 };
const result = postRes.filter((item) => filterFunction(item, ["mahmoud", "faizan"]));

console.log("result ", result);
about 4 years ago · Juan Pablo Isaza Report

0

if you like to solve by javascript methods, like many people pointed out

if (["mahmoud", "faizan"].some((v) => a.text.includes(v))) {
    return a;
  }

if you like regular expression, do this way

if(a.text.match(/(mahmoud|faizan)/)){
    return a
  }
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!