Checking for duplicate property values in an array of nested objects

I have a JSON file with an array that has nested objects and arrays that simulates a shopping cart. I want to check for duplicate values and if there are any, update the quantity value of the item otherwise, just add the items to the cart.

Here is the JSON file:

[
    {
        "email": "[email protected]",
        "status": "OPEN",
        "items": [
            {
                "name": "hamster",
                "quantity": 2,
                "price": 20
            },
            {
                "name": "saw dust",
                "quantity": 1,
                "price": 20
            },
            {
                "name": "hamster-cage",
                "quantity": 1,
                "price": 150
            },
            {
                "name": "book: how to care for your hamster",
                "quantity": 1,
                "price": 150
            },
            {
                "name": "hamster-cage",
                "quantity": 1,
                "price": 150
            }
        ]
    }
]

And here is what I have done so far:

const data = require("./data.json");

function checkIfPresent(key){
    let ans = data.findIndex((obj) => Object.values(obj).includes(key))
    return ans;
}

for(let x = 0; x < data.length; x++)
{
    let arr;
    if(checkIfPresent(data[x].items)){
        arr[ans].quantity += data[x].items.quantity;
    }else{
        arr.push(data[x].items);
    }
}

The code does not work the way it’s supposed to, please help.