Hi guys I am working on this live project where I want to store the quantity/count values (1,2,3…) locally. I just need a little guidance with the code. I am learning ionic. This is my ts files code snippet.
this.cartArr.push(items);
this.dataPrint = this.cartArr;
let item =this.dataPrint;
let selected = {};
for(let obj of item){
if(selected[obj.ITEMID]){
selected[obj.ITEMID].count++;
}else{
selected[obj.ITEMID] = {...obj,count: 1};
}
}
this.selectedItems = Object.keys(selected).map(key => selected[key])
console.log('items: ',this.selectedItems);
this.total = this.selectedItems.reduce((a, b) => a + (b.count * b.RATE), 0);
this.storage.set('cartItems',this.selectedItems);