Help with array of objects

hi i have an array of objects below where i need to return specific data.

const customers = [

    {

        "email": "tshepo@umuzi.org",

        "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

            }

        ]

    },

    {

        "email": "tshepo@umuzi.org",

        "status": "PAID",

        "items": [

            {

                "name": "balloons",

                "quantity": 1,

                "price": 25

            },

            {

                "name": "big friggin cake",

                "quantity": 1,

                "price": 150

            },

            {

                "name": "candles",

                "quantity": 1,

                "price": 30

            }

        ]

    }
]

This is the instructions:
//Write a function called get customer baskets that has an email address as an //argument and returns a list/array of all the shopping baskets that belong to //the customer with that email address.

//If the customer has no shopping baskets then return an empty list/array.

This below is what i have tried so far, i can only get the email address as in the param. Im struggling to match the email address with their specific shopping baskets and if they have no shopping baskets, ive tried and failed with map and filter methods too:

function getCustomerBaskets(customers, email) {

    var arr = [];

    for(var i = 0; i < customers.length; i ++) {

        var baskets = customers[i].items

        if(customers[i].email.includes(email)) {

            var userEmail = email //returns argument value

        }

        if(i[userEmail] && i[baskets]) {

            arr.push(baskets)

        }

    }

    console.log(arr)
}

getCustomerBaskets(customers, "tshepo@umuzi.org")

syntax error, i, is a number

I don’t understand what logic flow you are using

can you explain in words what is your plan to find and return the requested data?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.