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.