如何在将行推入数组后立即删除源上的行(表格)
How to delete rows on source right after they were pushed into an array (Sheets)
如何让它删除符合条件并被推入数组的行?
到目前为止,我得到了以下信息,但它给了我越界错误:
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.
}
}
在来源 sheet 上,我得到 headers
我已经看到删除行实际上是从下到上工作的,但是我如何才能 re-reference 在 for 循环中删除行?
谢谢!
向后循环:
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.
}
}
我会尝试这样的事情:
let headerData = []
let data = [];
const headerSize = 1;
for (let i = values.length - 1; i > headerSize; i--) {
if (values[i][0] === productCode) {
let row = [values[i][22],values[i][23],values[i][24],values[i][25]]
data = [row, ...data]
headerData = [headerValues[i], ...headerData]
sheet.deleteRow(i+1);
}
}
使用解构数组使值保持有序
如何让它删除符合条件并被推入数组的行?
到目前为止,我得到了以下信息,但它给了我越界错误:
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.
}
}
在来源 sheet 上,我得到 headers
我已经看到删除行实际上是从下到上工作的,但是我如何才能 re-reference 在 for 循环中删除行?
谢谢!
向后循环:
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.
}
}
我会尝试这样的事情:
let headerData = []
let data = [];
const headerSize = 1;
for (let i = values.length - 1; i > headerSize; i--) {
if (values[i][0] === productCode) {
let row = [values[i][22],values[i][23],values[i][24],values[i][25]]
data = [row, ...data]
headerData = [headerValues[i], ...headerData]
sheet.deleteRow(i+1);
}
}
使用解构数组使值保持有序