Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda