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

379
Visualizações
How do I loop an Array to check for words in a string? JavaScript

A little trouble here. Been working on these lines of code to receive string parameters from the checkBaggage() function which will then use the if/else statement to check for certain words e.g "Knife", "Gun" in the user input stored at variable baggage.

However, instead of writing those check words directly into the baggage.includes() method,

i.e

 if (baggage.includes('knife') || baggage.includes('gun')) {
      console.log('You are NOT allowed on board'); 
 };

I want it to loop through the array single to check for the words and then determine if they are present or not.

I need help! Thank you.

const checkBaggage = function (items) {
  const baggage = items.toLowerCase();

  const notAllowed = ['knife', 'gun', 'camera'];
  let single = [];
  for (const nota of notAllowed) {
    single.push([nota]);
  }
  // console.log(single)

  if (baggage.includes()) {
    console.log('You are NOT allowed on board');
  } else {
    console.log('Welcome aboard!');
  }
};

checkBaggage('I have a laptop, some Food and a pocket Knife');
checkBaggage('Socks and camera');
checkBaggage('Socks and Food');
checkBaggage('Got some snacks and a gun for protection');

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