I am trying to learn how destructuring works and encountered a challenge. I destructured results into a data variable and I was wondering how I would further destructure itemsInCart and buyerCountry.
function makeArray() {
return {
results: [
{
itemsInCart: [
{
name: "pizza",
price: 74,
qty: 1
},
{
name: "Pepper Soup",
price: 32,
qty: 2
}
],
buyerCountry: "Rwanda"
}
]
};
}
const {
results: [data]
} = makeArray();
console.log(data);
below is my output so far:
{
itemsInCart: [{
name: 'pizza',
price: 74,
qty: 1
},
{
name: 'Pepper Soup',
price: 32,
qty: 2
}
],
buyerCountry: 'Rwanda'
} => undefined
const {results: [{buyerCountry, itemsInCart}]} = makeArray().console.log(buyerCountry, itemsInCart);