你可能想做的是:
var x = [{
office: ("[email protected] /cdn-cgi/l/email-protection"),
home: ("[email protected] /cdn-cgi/l/email-protection"),
work: ("[email protected] /cdn-cgi/l/email-protection")
},
{
home: ("[email protected] /cdn-cgi/l/email-protection")
}]
and:
for(var j = 0; j < x.length; j++)
{
for(var anItem in x[j])
{
console.log(x[j][anItem])
}
}
// 编辑:
然而,这不是最佳实践 https://stackoverflow.com/questions/500504/javascript-for-in-with-arrays用于…中。
也许您可以将数据结构更改为:
var x = [[{
value: "[email protected] /cdn-cgi/l/email-protection",
type: "office"
},
{
value: "[email protected] /cdn-cgi/l/email-protection",
type: "home"
},
{
value: "[email protected] /cdn-cgi/l/email-protection",
type: "work"
}],
[{
value: "[email protected] /cdn-cgi/l/email-protection",
type: "home"
}]];
并迭代使用:
for( var i = 0, xlength = x.length; i < xlength; i++ )
{
for( var j=0, ylength = x[i].length; j < ylength; j++ )
{
console.log(x[i][j].value);
}
}