简体   繁体   English

Function“长度”在谷歌应用脚本中无法正常工作

[英]Function "length" not working properly in google apps script

I made function in the google sheet我在谷歌表中制作了 function

function AVG_ZERO(input) {
  return input.length
};

But length of array different If the range of numbers is located in a column, then it is considered correct If the range of numbers is located in a string, then the length is 1 Links to images: https://postimg.cc/56xfmhZh https://postimg.cc/HVc13T6P但是数组的长度不同如果数字范围位于一列中,则认为正确如果数字范围位于字符串中,则长度为1 链接到图片: https://postimg.cc/56xfmhZh https://postimg.cc/HVc13T6P

Try unfolding the array by using the Array.flat() function into separate elements regardless of the orientation:尝试使用Array.flat() function 将数组展开为单独的元素,无论方向如何:

function AVG_ZERO(input) {
  return input.flat().length
};

That will give you 3 for both row and column.这将为您提供行和列的 3。

在此处输入图像描述

Issue:问题:

If you pass a range of cells as an argument of a custom function, the argument will be treated by your custom function as a two-dimensional array of the cell's values, with the inner arrays being the individual rows.如果您将一系列单元格作为自定义 function 的参数传递,则自定义 function 将把该参数视为单元格值的二维数组,内部 ZA3CBC3F9D0CE2F2C1554ZE1B67 是单独的行。 That is, the outer array length will equal the number of rows in your range: 1 for B1:D1 and 3 for B1:B3 .也就是说,外部数组length将等于您的范围内的行数:1 代表B1:D1和 3 代表B1:B3

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM