All I'm trying to do is filter a list of stores, store it in a new variable object called grapefruitStores, and print it to the console in JavaScript. I'm allowed to use filter, map, and reduce. Here's what I have so far:
const stores = [{
name: "Kents",
foods: [
{name: 'bagels', type: 'grain'},
{name: 'bread', type: 'grain'},
{name: 'cereal', type: 'grain'},
{name: 'milk', type: 'dairy'},
]
},{
name: "Maceys",
foods: [
{name: 'bagels', type: 'grain'},
{name: 'bread', type: 'grain'},
{name: 'cereal', type: 'grain'},
{name: 'grapefruit', type: 'fruit'},
{name: 'milk', type: 'dairy'},
]
}];
//Filtering code
function sellsGrapefruit(stores) {
return stores.foods.name === 'grapefruit'; //Don't think this is correct.
}
var grapefruitStores = store.filter(sellsGrapefruit);
console.log(grapefruitStores);
So, only the Maceys object information should print to the console since Maceys sells grapefruit and Kents does not. An empty array/object keeps printing to the screen, and I'm not sure why. What am I doing wrong here? Any help would be appreciated.
foodsis array in each one...an array can't have a propertyname. Need to iterate thefoodsarraystore.foods.filter(function(food) { return food.name === 'grapefruit'; })