在使用Array.includes时,需要注意其参数是否是一个完整的元素。如果想要检查数组中是否包含某个字符串,可以使用Array.join将数组转换为字符串,再使用string.includes进行检查。例如:
const words = ["hello", "world", "example"]; const sentence = words.join(" "); console.log(sentence.includes("hello")); // true
在上述代码中,将数组words转换为了字符串,再使用string.includes检查是否包含字符串"hello",输出结果为true。