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

208
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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