I am comparing two arrays for matched items but I need to make them case insensitive.
here is the code: credit for this code to @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)
)
)
I was able to get the second part to lower case by doing words.includes(description.toLowerCase())
but I don't know how to handle the first part: texts.some(({ description })
I should mention I have tried adding toLowerCase() to { description } like this: { description.toLowerCase() }
but this does not work
any help is greatly appreciated
Switch either to the function some
or function find
or function findIndex
.
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.some((w) => w.toLowerCase() === description.toLowerCase())));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With