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

378
Views
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
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!