How do I make this include words from the array that has uppercase letters?
const array = ["amassment", "amassments", "Amasta", "amasthenic", "amasty", "amastia", "AMAT", "Amata", "amate"]
const word = array.filter(m=> m.includes(args[0]))
const wrd = word.toLowerCase()
if(!wrd) return message.delete()
console.log(`${wrd}`)
When my args[0] is "am", it only sends "amassment"
, "amassments"
, "amasthenic"
, "amasty"
, "amastia"
, "amate"
. It doesn't include words in uppercase at all.
Even though I added the .toLowerCase()
, I get an error word.toLowerCase() is not a function
. I need help.
CodePudding user response:
You have to call toLowerCase() inside filter function.
const word = array.filter(m=> m.toLowerCase().includes(args[0]))
If your args also needs to be lower cased and included, you can use the below approach to check
const word = array.filter(m=> m.match(new RegExp(args[0],"i")));