Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda