I am trying to make an inventory system where when an item is obtained it will only put the item into the array if it does not already exist in the array. Then regardless of whether it was put into the array or not, find the item in the array and increase its amount by 1. This is what I have at the moment:
function newItem(){
apple = new uniqueItem("apple", "resources/apple.png")
if (inventory.indexOf(apple) != null){
inventory.push(apple)
}
inventory[inventory.indexOf(apple)].amount += 1
}
Im still pretty new to javascript and I would appreciate it if someone could point me in the right direction
indexOf(object)? I guess you should deal with the keys of the object..var arr=[{a:10},{b:20}]; var a={a:10}; arr.indexOf(a);will be-1