Currently, I am utilizing Vue.js along with JavaScript.
In my code, there is an array of objects named products
, each containing a special property called smallest_unit_barcode
. My goal is to filter out only those products that have a barcode similar to a given value
. To achieve this, I implemented the following function:
if (value != '') {
var results = this.products.filter(obj=>obj.smallest_unit_barcode.includes(value));
var results = results.slice(Math.max(results.length - 20, 0))
this.pos_quick_lunch = results;
}
While everything seems to be working smoothly, I encountered an issue when
obj.smallest_unit_barcode == null
, resulting in the following error message:
Error in v-on handler: "TypeError: Cannot read property 'includes' of null"
My concern now is how to overlook the null
value while filtering the products array?