你可以用 Array.prototype.some() 方法巧妙判断字符串中是否包含数组中的任意单词。例如:

// 判断 str 是否包含 arr 中任意一个单词
const arr = ['apple', 'banana', 'cat']
const str = 'I have a banana and an orange.'
const hasWord = arr.some(word => str.includes(word))
console.log(hasWord) // true

如果需要判断为 “完整单词” 而不是子串,可以用正则:

const arr = ['apple', 'banana', 'cat']
const str = 'I have a banana and an orange.'
const hasWord = arr.some(word => new RegExp(`\\b${word}\\b`).test(str))
console.log(hasWord) // true

这样写法简洁且高效。