【发布时间】:2021-07-19 05:55:24
【问题描述】:
我想实现这样的目标:
如果数组 [ "a", "b", "c"] 包含 const word 的任何字符 = "abracadabra" 给我该字符及其在 const word 中的位置
我尝试过这样的事情:
const word = "abracadabra";
const input = ["a", "b", "c"];
for (let i = 0; i< word.length; i++) {
if (input.includes(word(i))) {
console.log(i + (word(i)));
}
}
但这不起作用,有人可以帮助我了解逻辑和/或语法吗? 我是编码新手,感谢您的时间和精力!
【问题讨论】:
-
你知道
word(i)和word[i]的区别吗? -
“不起作用”不是计算机所说的。它说“单词不是函数”,这清楚地表明问题出在哪里 - 您正在尝试使用不是函数的东西作为函数。
-
感谢您的提示!
标签: javascript arrays string include