将行推入数组后如何立即删除源行(表) [英] How to delete rows on source right after they were pushed into an array (Sheets)
本文介绍了将行推入数组后如何立即删除源行(表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使它删除符合条件并被推入数组的行?
How to make to make it delete the rows that match a criteria and were pushed into an array?
到目前为止,我得到了以下信息,但它给了我超出范围的错误:
So far, I got the following, but it gives me out of bounds error:
for (var i = 1; i < values.length; i++) {
if (values[i][0] == productCode) {
data.push([values[i][22],values[i][23],values[i][24],values[i][25]]); //This array is for a certain purpose.
headerData.push(headerValues[i]);//This array is for another certain purpose.
sheet.deleteRow(i+1); //This is the one I'm having trouble with.
}
}
在源工作表上,我有标题
On Source sheet, I got headers
我已经看到删除行实际上是自下而上工作的,但是我如何在for循环中重新引用i行呢?
I've seen that delete row actually works from bottom to top, but how I can re-reference i rows within that for loop?
谢谢!
推荐答案
向后循环:
for (var i = (values.length-1); i > 0; i--) {
if (values[i][0] == productCode) {
data.push([values[i][22],values[i][23],values[i][24],values[i][25]]); //This array is for a certain purpose.
headerData.push(headerValues[i]);//This array is for another certain purpose.
sheet.deleteRow(i+1); //This is the one I'm having trouble with.
}
}
这篇关于将行推入数组后如何立即删除源行(表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文