Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

380
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda