I come from a Python background so I am fairly new when it comes to iterating through JS objects. With Python you can create nested for loops to get into Key value pairs. My question is how do I iterate through this object and append the values greater than given number to an array.
The object I need to iterate through
const foodmenu = {
title: 'Menu',
sections: [
{
title: 'App',
items: [
{
title: 'Cookie',
available: true,
price: 3
},
{
title: 'Snicker',
available: true,
price: 12
},
{
title: 'Donuts',
available: true,
price: 11
}
]
},
{
title: 'FullMeal',
items: [
{
title: 'Steak',
available: false,
price: 33
},
{
title: 'Chinese Chicken',
available: true,
price: 14
},
{
title: 'Fried Chicken',
available: false,
price: 17
}
]
},
]
}
So to begin I need to create a function that takes in a number for price and take in the object. So this is what I tried so far, I don't know all of JS syntax but it's more pseudocode than working code at this point.
function findPriceAbove(price, foodmenu){
//create empty array to append the key names and values, E.G. ['App-Cookie(3)']
const abovePriceArray = []
for (var key in foodmenu){
if (foodmenu.hasOwnProperty(key)){
for (const [key, value] of Object.entries(foodmenu)) {
if foodmenu[value] > price and available == true;
abovePriceArray.push(key(App),name(Cookie),value(3)
}
}
}
return abovePriceArray
}