React использую впервые, с JS только знакомлюсь. Помогите понять как правильно в моем случае сделать проверку на null что бы это сработало. Я настроил поиск и фильтр по полям, но стоит появится значению null и все ломается. Проверки по типу if(!result) / if(result === null) / if(result === " ") / if(result === undefined) не дают результата. Использовал в проекте Lodash.
getFilteredData() {
const { data, search } = this.state;
if (!search) {
return data;
}
var result = data.filter((payment) => {
return (
payment["id"].toString().includes(search.toString()) ||
payment["status"]
.toString()
.toLowerCase()
.includes(search.toString().toLowerCase()) ||
payment["token"].toString().includes(search.toString()) ||
payment["currency"].toLowerCase().includes(search.toLowerCase()) ||
payment["product"].toString().includes(search.toString()) ||
payment["redirect_success_url"]
.toString()
.includes(search.toString()) ||
payment["redirect_fail_url"].toString().includes(search.toString()) ||
payment["amount"].toString().includes(search.toString()) ||
payment["created_at"].toString().includes(search.toString()) ||
payment["updated_at"].toString().includes(search.toString()) ||
payment["extra_return_param"].toString().includes(search.toString()) ||
payment["operation_type"].toString().includes(search.toString()) ||
payment["order_number"].toString().includes(search.toString())
payment["card_masked_number"].toString().includes(search.toString()) ||
payment["uid"].toString().includes(search.toString())
);
});
if (!result.length) {
result = this.state.data;
}
return result;}
Вываливается в ошибку TypeError: Cannot read property 'toString' of null. В некоторых полях есть смешанный тип данных, например ссылка или токен, где есть и цифры и символы, уже спрашивал - посоветовали приводить к строке.