我有一个这种形式的json:
var test = { "name1" : [ "aaa", "bbb"], "name2" : [ "ccc", "ddd" ] };
我试图像
那样迭代这个for (var names in test )
{
for ( var element in names )
{
// problem we got the chars in the "names1", etc
}
}
我到底错过了什么?
答案 0 :(得分:1)
要迭代test
对象,你需要这样的东西:
for(var key in test) //iterate object keys
{
var elements = test[key];
for(var i = 0; i < elements.length; i++) //iterate array indexes
{
var element = elements[i];
}
}