When I run this code
return (
val.ticket.ticketNumber.toLowerCase().includes(inputText) ||
val.ticket.source.toLowerCase().includes(inputText) ||
val.ticket.lagoonMaterial.toLowerCase().includes(inputText) ||
val.ticket.vendor.toLowerCase().includes(inputText) ||
val.ticket.gallons.toLowerCase().includes(inputText);
);
Sometimes one the properties is missing and that gives me this error
TypeError: undefined is not an object (evaluating 'val.ticket.vendor.toLowerCase')
How can I dismiss this property without having to use if statement?
Use nullish coalescing operators. It's like an OR (||), but it only works for null and undefined values. The placement of ?? is just like ||
function getValue(num) {
return num ?? 'Pass a number';
}
console.log(getValue(5));
console.log(getValue());