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

210
Views
¿Cómo verificar si un argumento/parámetro está dentro de una constante ya definida en JavaScript?

Estoy haciendo un pequeño bot en javascript que debería detectar lo que escribo y dar una respuesta. En este caso, este comando "mirar" tiene varios argumentos/parámetros como a, b y c. Quiero una respuesta afirmativa solo si el argumento/parámetro que digo está dentro de "look". Y uno negativo si no lo es. Supuse que esto se hace usando "si", pero no puedo entender cómo.

Ejemplo... La const con sus argumentos/parámetros:

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

Lo que realmente espero de ella que diga:

 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.')

Si digo "mira z", ella debería decir la segunda respuesta.

Pero por alguna razón (Obviamente estoy haciendo algo mal) en ambos, ella no hace nada y sigue ejecutando el siguiente código que tiene.

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

0

Está probando si args[0] es la palabra hi , no si está en la matriz con ese nombre. Entonces solo funcionará si escribes look hi .

Use includes() para probar si algo está en una matriz y no ponga comillas alrededor del nombre de la variable.

 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!