【发布时间】:2019-03-01 23:13:06
【问题描述】:
我正在比较两个数组的匹配项,但我需要使它们不区分大小写。
这是代码:此代码归功于@PatrickRoberts here
const words = ['word1', 'word2', 'word3']
const texts = [
{name: 'blah', description: 'word4'},
{name: 'blah2', description: 'word1'},
{name: 'blah3', description: 'word5'}
]
console.log(
texts.some(
({ description }) => words.includes(description)
)
)
我可以通过 words.includes(description.toLowerCase()) 将第二部分变为小写,但我不知道如何处理第一部分:texts.some(({ description }) 我应该提到我已经尝试将 toLowerCase() 添加到 { description } 之类这个:{ description.toLowerCase() } 但这不起作用
非常感谢任何帮助
【问题讨论】:
标签: javascript arrays array-filter