将一个数组推到另一个数组的末尾 [英] Push one array to the end of another

查看:64
本文介绍了将一个数组推到另一个数组的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是GAS的新手。我有两个数组。 AR1有7个列和16行。 AR2有7个列和4行。我想将小阵列(AR2)推到大阵列(AR1)的底部,以使AR1具有7个列和20行。这是我的代码:

I am new to GAS. I have two arrays. AR1 has 7 cols and 16 rows. AR2 has 7 cols and 4 rows. I want to push the small array (AR2) to the bottom of the big array (AR1) for AR1 to have 7 cols and 20 rows. This is my code:

AR1.push(AR2);

当我通过将AR1的值设置到活动工作表(sh)中来检查是否有新数据时:

When I check if there is new data by setting the values of AR1 into the active sheet (sh):

sh.getRange(1,1,AR1.length,AR1[0].length).setValues(AR1)

我得到一个错误:
例外:数据中的列数与范围中的列数不匹配。数据有4个,但范围有7个。
并且AR1以未更改的形式写在活动表中,具有7个列和16行。

I get an error: Exception: The number of columns in the data does not match the number of columns in the range. The data has 4 but the range has 7. And AR1 is written in the unchanged form in the active sheet with 7 cols and 16 rows.

它看起来像转置了AR2在推送命令中和/或没有推送到AR1的末尾,但我不知道为什么或如何解决它。

It looks like AR2 is transposed in push command and/or not pushed to the end of AR1, but I don't understand why or how to fix it. Any help is highly appreciated.

推荐答案

这可能应该起作用:

AR1.push(...AR2);

参考文献:

传播语法

这篇关于将一个数组推到另一个数组的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆