Here is my code:
if(basketdata.length > 0){
for(var i = 0 ;i<basketdata.length; i++){
//update quantity in list if same item is selected more than one time
if(temp.id == basketdata[i].id){
console.log('updateitem');
basketdata[i].quantity = addQuantity;
break;
}else{
basketdata.push(temp);
break;
}
}
}else{
console.log('newitem');
basketdata.push(temp);
}
I have flatlist with two buttons plus and minus in my React Native application. If user clicks the item in list I want to add that item in array and again if user tried to click the same item I want to update the quantity parameter in the item instead of adding new item.
Notes:
- I want to update the item if user selects same item
- Add new item in array if user selects different item in flatlist
I tried as much as possible to fix but I am not able to make actual output.