0

I would like to check the nullable object to toUpperCase.

Here is example=>

this.state.holidays.filter(e=>e.holidd.toUpperCase().includes(this.state.searchvalue.toUpperCase()) ||
                           e.holidesc.toUpperCase().includes(this.state.searchvalue.toUpperCase()));

This holidesc is can be null and null value can't check toUpperCase.So How can I save check?

Arkar
  • 53
  • 1
  • 6

1 Answers1

1

Just check for null value first;

this.state.holidays.filter(
    e=>e.holidd.toUpperCase().includes(this.state.searchvalue.toUpperCase()) 
    ||
    (e.holidesc && e.holidesc.toUpperCase().includes(this.state.searchvalue.toUpperCase())));

How do I check for null values in JavaScript?

0stone0
  • 34,288
  • 4
  • 39
  • 64