我在Google应用脚本中有一个二维数组
data = [[1, 2], [3, 4]];
尝试获取数据的长度返回"未定义"。那是为什么?
Logger.log(data.length) // Outputs "Undefined"
更新(完整代码):
data = sheet.getSheetValues(1, 1, 10, 2);
Logger.log("readSpreadSheet");
Logger.log(data);
Logger.log(data.lenght);
日志:
[14-02-10 15:05:05:592 CET] readSpreadSheet
[14-02-10 15:05:05:592 CET] [[tt0062622, 10.0], [tt0066921, 10.0], [tt0094721, 8.0], [tt0445934, 10.0], [tt0784972, 7.0], [tt1136608, 1.0], [tt0119116, 10.0], [tt1195478, 7.0], [tt2234155, 1.0], [tt1675434, 9.0]]
[14-02-10 15:05:05:592 CET] undefined
答案 0 :(得分:8)
你在代码中输错了...
您写了lenght
而不是length
代码:
data = sheet.getSheetValues(1, 1, 10, 2);
Logger.log("readSpreadSheet");
Logger.log(data);
Logger.log(data.length);
日志:
data.length = 10