Search code examples
javascriptreactjsuse-effect

How to use toLowerCase() function before filter?


enter image description here

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?


Solution

  • 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 ....