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

203
Views
How to check if an argument/parameter is inside a const already defined on JavaScript?

I am doing a little bot on javascript that should detect what i write and give an answer. In this case this command "look" has several arguments/parameters like a, b and c. I want an affirmative answer only if the argument/parameter that i say its inside "look". And a negative one if is not. I guessed that this is made by using "if" but i cant figure how so.

Example... The const with its arguments/parameters:

const hi = [ 'a', 'b, 'c' ] // This has worked for me before.

What i actually expect from her to say:

look a
if (args[0] == "hi") return reply('Done, its there! :D') 
if (!args[0] == "hi") return reply('Its not there. I cant make magic things.')

If i say "look z" she should say the second answer.

But for some reason (Obviusly im doing something wrong) on both she doesnt do anything and keeps executing the next code she has.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're testing if args[0] is the word hi, not if it's in the array with that name. So it will only work if you write look hi.

Use includes() to test if something is in an array, and don't put quotes around the variable name.

if (hi.includes(args[0])) {
    return reply('Done, its there! :D');
} else {
    return reply('Its not there. I cant make magic things.')
}
about 4 years ago · Juan Pablo Isaza Report
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!