var locations = [
["Steve","New York"]
,["Abigayle","Chicago"]
];
或者
var locations = [
{Name:"Steve",Location:"New York"}
,{Name:"Abigayle",Location:"Chicago"}
];
您可以像这样在第一个选项中输出数据:
var delimiter = " ";
console.log("var locations = [");
for (var i=0; i<locations.length; i++)
{
var innerdelimiter = "";
var line = delimiter + "[";
for (var j=0; j<locations[i].length;j++)
{
line += innerdelimter + locations[i][j];
innerdelimiter = ",";
}
line += "]";
console.log(line);
delimiter = " ,";
}
console.log("];");
和第二个选项中的数据如下:
var delimiter = " ";
console.log("var locations = [");
for (var key in locations)
{
console.log(delimiter + "{" + key + ":" + locations[key] + "}");
delimiter = " ,";
}
console.log("];");