我有以下内容:
var nr_0 = new Array("","","");
var nr_1 = new Array("","","");
var nr_2 = new Array("","","");
var nr_3 = new Array("","","");
var nr_4 = new Array("","","");
依旧......
有没有办法计算使用了多少个数组。所以在这种情况下,它会出现一个数字为5的字符串
谢谢。答案 0 :(得分:2)
将它们保存为1个数组而不是多个变量:
var nr = [
new Array("","",""),
new Array("","",""),
new Array("","",""),
new Array("","",""),
new Array("","","")
];
console.log(nr.length);
顺便说一句,这更优雅:
var nr = [
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""]
];
console.log(nr.length);