const items = [
{ item: "apple", cost: 2 },
{ item: "orange", cost: 4 },
{ item: "carrot", cost: "" },
{ item: "grapes", cost: 5 },
{ item: "milk", cost: 3 },
{ item: "bread", cost: " " },
];
const pricesByItem = function (array) {
array.map((elem) => {
let result = {};
result[elem.item] = elem.cost;
return result;
});
};
console.log(pricesByItem(items))
Hey there, I'm attempting to use map() to match each item in the array with its respective cost, but the function is giving me undefined as output.
I've tried debugging my code and noticed that the output variable holds values while going through the array, however, it ultimately returns undefined. I'm fairly new to programming and can't figure out the reason behind this issue. Thanks for your help!