gpt4 book ai didi

javascript - 解构数组

转载 作者:行者123 更新时间:2023-12-03 03:07:10 26 4
gpt4 key购买 nike

我已经编写了一个小脚本,如果行的“已邮寄”字段中没有"is",则通过电子邮件发送(Google 表格)。它工作正常,但我想使用数据行中的格式化文本来增强电子邮件。

我需要帮助将此变量的数据分解为多个变量以便在电子邮件中使用。

var rangeSelect = auxSheet2.getRange(i, 1, 1, auxSheet2.getLastColumn()).getValues();

日志输出是正确的,看起来像这样......

[17-11-04 12:49:38:534 PDT] [[Tue Oct 03 00:00:00 GMT-05:00 2017, Captain, America, Engineering, 573-555-5555, me@mycompany.com, Equipment, Yes, We have two old 19" VGA monitors, , Test Submission 1, Yes]]

这是代码:

function moveAfter() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var auxSheet2 = ss.getSheetByName("Auxiliary");
var lastColumn = auxSheet2.getLastColumn();

for (var i = auxSheet2.getLastRow(); i > 1; i--) {

var yesMailed = auxSheet2.getRange(i, 12).getValue();
if (yesMailed != "Yes") {
var targetCell = auxSheet2.getRange(i, 12);
targetCell.setValue("Yes")

var rangeSelect = auxSheet2.getRange(i, 1, 1, auxSheet2.getLastColumn()).getValues();
Logger.log(rangeSelect)

var recipients = "me@work";
var message = 'This is a test ';
var subject = 'New item for the Auxiliary Annual Garage Sale';
var body = message + ' Visit ' + ss.getUrl() + ' to view the changes';
MailApp.sendEmail(recipients, subject, body);
}
}
}

感谢您的帮助。

最佳答案

getValues方法返回值的二维数组(行、列)。

由于您正在拉取一行,因此您将对 getValues 数组的第一个(也是唯一一个)条目感兴趣,然后根据位置该行的编号索引。例如:

var rangeRows = auxSheet2.getRange(i, 1, 1, auxSheet2.getLastColumn()).getValues();
var row = rangeRows[0];
// get a single element
var myEmail = row[5];
// make a string out of a couple of elements of row
var sometext = "My Fave Superhero is " + row[1] + " " + row[2];
// or join the whole row with commas
var joinedRecord = row.join(",");

关于javascript - 解构数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47115276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com