Arkar
Arkar

Reputation: 53

How to save check to nullable object in react

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?

Upvotes: 0

Views: 236

Answers (1)

0stone0
0stone0

Reputation: 44102

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?

Upvotes: 1

Related Questions