как перебрать такой обьект?
const pizza = {
cap: {
dough: 1,
tomato_sauce: 1,
onion: 2,
sausage: 2,
mashroom: 3,
cheese: 1,
},
onions: {
dough: 1,
tomato_sauce: 1,
onion: 2,
meat: 1,
cheese: 1,
},
king_one: {
dough: 1,
tomato_sauce: 1,
onion: 2,
mayo: 1,
mashroom: 3,
tomato: 2,
cheese: 3,
dill: 2,
parsley: 2,
},
gavay: {
dough: 1,
tomato_sauce: 1,
onion: 2,
ananas: 1,
cheese: 2,
},
tonno: {
dough: 1,
tomato_sauce: 1,
tuna: 2,
kappers: 1,
cheese: 1,
},
vegeterian: {
dough: 1,
tomato_sauce: 1,
tomato: 2,
kappers: 1,
cucumber: 2,
onion: 2,
cheese: 1,
},
};
Ответы (1 шт):
Автор решения: essle
→ Ссылка
Например, так:
Object.entries(pizza).map(([type, items]) => {
Object.entries(items).map(([item, count]) => {
console.log(type, item, count)
})
});
Но перебрать можно по разному, поэтому уточните что именно нужно сделать.