I want to lowercase product.productName before filter, but I couldn't do that. I tried some thing but didn't work. Is there any way that I can lowercase product.productName before filter?
CodePudding user response:
.map()
could be used as a step before filter()
products
.map(product => product.productName.toLowerCase())
.filter(...)
CodePudding user response:
Simply convert to lowercase inside filter before comparing.
e.g.
product.productName.toLowerCase().includes ....
.
If it complains about being an object, convert to string first.
product.productName.toString().toLowerCase().includes ....