如何检查 argument/parameter 是否在已经在 JavaScript 上定义的 const 中?

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

我正在 javascript 上做一个小机器人,它应该检测我写的内容并给出答案。在这种情况下,此命令“look”有多个 arguments/parameters,如 a、b 和 c。只有当我说它里面的 argument/parameter 是“看起来”时,我才想要一个肯定的答案。如果不是,则为负数。我猜这是用“如果”做的,但我不知道怎么会这样。

例子... const 及其 arguments/parameters:

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

我真正希望她说的话:

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

如果我说“look z”,她应该说第二个答案。

但出于某种原因(显然我做错了什么)她什么也没做,并继续执行她的下一个代码。

您正在测试 args[0] 是否是单词 hi,而不是它是否在具有该名称的数组中。所以它只有在你写 look hi.

时才有效

使用 includes() 来测试数组中是否有内容,不要在变量名两边加上引号。

if (hi.includes(args[0])) {
    return reply('Done, its there! :D');
} else {
    return reply('Its not there. I cant make magic things.')
}