const myproducts = ref([])
const items = ref([
{ id: 1, item: 'Vaporub 50Gm' , barcode: '123456'},
{ id: 2, item: 'Herbal Cool Oil (300+100)Ml', barcode: '123456' },
{ id: 3, item: 'live Oil Bp 70Ml', barcode: '123456' }
]
const selectedProducts = function(id) {
var exists = myproducts.value.some(function(field) {
return field.id === id;
});
if (!exists) {
myproducts.value.push( '{id:'+ id +', qty:'+ 1 +'}' );
console.log("clicked on ", id );
} else {
console.log("Already exist on ", id );
}
}
Is there a way to determine whether the provided ID exists within the myproducts
array? The function above doesn't seem to be yielding any results.