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

144
Views
How to do a partial match filter on an array from all elements of another array

I'm trying to filter an array with partial matches from the entirety of another array. For example, the arrays are outlined below:

Array1 = 
     categories: 292300, 
     categories: 300, 
     categories: 292500280

Array2 = 
     300,
     498

With the filter, I would expect to return:

NewArray = 
     categories: 292300, 
     categories: 300

What is the best way to implement this? I've tried the code below with no luck:

  const NewArray = Array1.filter(Array1 => !(Array1.categories.includes(Array2)))
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Why new array also includes 292300 while it's not included in array2?

But if you want to filter array1 with data included in array2, there is the solution

const NewArray = Array1.filter(({ categories }) => Array2.includes(categories))

about 4 years ago · Juan Pablo Isaza Report

0

  const Array1 = [{ categories: 292300 }, { categories: 300 }, { categories: 292500280 }];

  const Array2 = [300, 498];
  const newArray = [];

  Array2.forEach((el) => {
    Array1.forEach((element) => {
      if (element.categories.toString().includes(el.toString())) {
        newArray.push(element);
      }
    });
  });
about 4 years ago · Juan Pablo Isaza Report

0

To do partal matching just need parse int to string

const arr1 = [{categories: 292300}, {categories: 300}, {categories: 292500280}];
const arr2 = [300, 498];

const result = arr1.filter(({ categories }) => 
  arr2.some((e) => String(categories).includes(String(e))));

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!