我有一个JavaScript数组:
Fruit > Banana > Colour > Yellow
> Size > Large
> Cost > $3.50
> Apple > Colour > Green
> Size > Small
> Cost > $0.42
我可以使用以下方法获取值:
alert(Fruit['Banana']['Colour']);
如何使用索引获取相同的值?例如:
alert(Fruit[0][0]);
感谢大家为我指引正确的方向,这是我需要的解决方案:
for (var a in Fruit) {
//var a gives me "Banana" and "Apple"
for (var b in Fruit[a]){
//var b gives me "Colour", "Size" and "Cost"
//Fruit[a][b] gives me the values
}
}