I want to check an array and find the array that contains a certain thing
I have a cartarray that contains these values
{id: "1510-01-312-3501-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514542566148", name: "AIRPLANE UTILITY", price: "$90", quantity: "1"}
{id: "1510-01-312-3501-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514542566148", name: "AIRPLANE UTILITY", price: "$90", quantity: "1"}
{id: "1510-00-033-6312-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514540733034", name: "AIRPLANE UTILITY", price: "$43", quantity: "3"}
{id: "1510-00-033-6312-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514540733034", name: "AIRPLANE UTILITY", price: "$43", quantity: "1"}
{id: "1510-00-033-6312-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514540733034", name: "AIRPLANE UTILITY", price: "$43", quantity: "1"}
each of the object represent a product what I really want to do is prevent duplication of id so if the id are the same, I want to consolidate the quantities. so before I add a new product object of this format
{id: "1510-00-033-6312-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514540733034", name: "AIRPLANE UTILITY", price: "$43", quantity: "7"}
I want to check if there is similar productid in the cartarray
var arrayLength = cartarry.length;
for (var i = 0; i < arrayLength; i++) {
if (cartarry[i] == product.id ){
console.log("we got a match")
var updatedquantity = quantity + parseInt(product.quantity)
}
}
I tried couple of different method but unsuccessful. How can i find the matching id and update the quantity ? I hope i am clear in my description