我试图改进我的 javascript 在这里遇到了一些死胡同。
var schemes = {
"own" : {
"creatures" : ["creature1","creature2","creature3","creature4"],
"spells" : ["spell1","spell2","spell3","spell4"],
"items" : ["item1","item2","item3","item4"]
},
"enemy" : {
"creatures" : ["creature1","creature2","creature3","hidden"],
"spells" : ["spell1","spell2","hidden","hidden"],
"items" : ["item1","item2","item3","hidden"]
}
};
这是我的阵列。
然后我尝试为每个(我从 php 知道)做一个,但似乎 javascript 认为方案是一个对象,因此无法做一个:
for (var i=0;i<schemes.length;i++) {
//code
}
我错过了什么?scheme.length 说未定义