And this is the result.
What I am trying to achieve is increasing the quantity (coloured green) by 1 when an item is added. For some reason, the function adds another row and the amount is set at 2.
I’m wondering what I’m missing to make this function as intended.
I do see what you’ve done differently, I’ve made the adjustments, but this is the result; it’s just a new entry with no other data but the adjusted quantity. The quantity has not been added to the existing item.
I’m wondering if it’s because I’m trying to find the item in the array that is equal to the one I am trying to add, but since I am setting the array elem to only account for quantity, that’s why it’s adding a new entry in such a manner.
For updating you definitely need to get the exiting items index in the inventory array. If that doesn’t match then set array element will create a new entry.
Based on your structure you need to Loop the inventory.