我正在尝试创建一个接收任何数组并转置它的函数,以便行转换为列,列转换为行.
不知道我做错了什么或丢失了但是一旦数组通过就继续得到这个消息....
TypeError:无法将undefined的属性"0.0"设置为"xxxxxx".
错误在线
result [row] [col] = array [col] [row]; //旋转
任何指针都将非常感激.
function transposeArray(array){
var result = [];
for(var row = 0; row < array.length; row++){ // Loop over rows
for(var col = 0; col < array[row].length; col++){ // Loop over columns
result[row][col] = array[col][row]; // Rotate
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud) javascript multidimensional-array google-sheets google-apps-script
我需要在 Google Sheet Spreadsheet 中使用查询来返回给定长度的 B 列中的文本,以及其他各种条件。为方便起见,下面是一个仅专注于 Len() 函数的简化版本。看起来很简单,但不幸的是不起作用。
=QUERY(Valuations!B1:B,"select B where LEN(B)>3 ")
Run Code Online (Sandbox Code Playgroud)
我知道 SQL 使用 LEN(),而 LENGTH() 用于 MySQL。
我的语法不正确还是无法在 Google Sheet Query 中检查字符串长度?
我能否获得有关如何使用 JavaScript 从二维数组中提取多列(如下所示)的指导?
Array = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9,10,11,12],
];
Run Code Online (Sandbox Code Playgroud)
到目前为止我所看到的使用 forEach 或 map 的简单方法将允许一次提取一列,有没有一种方法可以以某种方式嵌套它以提取所需的任何列索引?
假设期望输出列是 1,2 和 4。
Output = [
[1, 2, 4],
[5, 6, 8],
[9,10,12],
];
Run Code Online (Sandbox Code Playgroud)
编辑:
我需要解决的另一个问题是如何删除 Array[i][1]=0 或空的行。
假设我们有额外的数组元素......
Array = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9,10,11,12],
[13,0,15,16],
[17, ,19,20],
[21,22,23,24],
];
Run Code Online (Sandbox Code Playgroud)
现在所需的输出是...
Output = [
[1, 2, 4],
[5, 6, 8],
[9,10,12],
[21,22,24],
];
Run Code Online (Sandbox Code Playgroud)