我可以有一个像下面“成分”的值这样的双重嵌套对象文字(语法是否正确)?
recipes = [
{name: 'Zucchini Muffins', url: 'pdfs/recipes/Zucchini Muffins.pdf',
ingredients: [{name: 'carrot', amount: 13, unit: 'oz' },
{name: 'Zucchini', amount: 3, unit: 'sticks'}]
}
];
如果是这样,我将如何访问“成分”对象的“单位”值?
我可以做这样的事情吗?
伪代码
for each recipes as recipe
print "this recipe requires"
for each recipe.ingredients as ingredients
ingredients.amount + " " + ingredients.unit;
(我正在考虑使用javascript)