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

164
Visualizações
How to remove from an array the elements that are present in a second array

I'm trying to clean an array (secondArray) by removing those elements that are also included in another array (secondRegex). This is one of my latest attempts, but it doesn't work :'( The result I get is: 0[]. Why????????

const secondRegex = ['i', 'a', 'about', 'am', 'an', 'are', 'as', 'at', 'be', 'by', 'for', 'from', 'how', 'in', 'is', 'it', 'of', 'on', 'or', 'that', 'the', 'this', 'to', 'was', 'what', 'when', 'where', 'who', 'will', 'with'];
const secondArray = ['i', 'am','a', 'very', 'happy', 'child'];

let myList = []
for (let i = 0; i < secondArray; i++){
    let is_the_same = 0;
    for (let j = 0; j < secondRegex; j++){
        if(secondArray[i] == secondRegex[j]){
            is_the_same = 1;
            break;

        }
    }if (!is_the_same){
        myList.push(secondArray[i]);
    }
}
console.log(myList);

I have also tried this with no success:

for (let i = 0; i < secondArray.length; i++){
    let value = secondArray[i];
    let coincidence = secondArray.some(value => secondRegex.includes(value));
    }if (coincidence = true){
        continue;
    }
    else{
    myList.push(secondArray[i]);
}       
about 4 years ago · Juan Pablo Isaza
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