Reputation: 53
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
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