获取数组中的第一列

hup*_*upf 5 google-sheets google-apps-script

我有一张工作表,需要获取某个列的值(电子邮件地址),在本例中为 C。假设列中有三封电子邮件。日志给了我:

“[[email1]、[email2]、[email3]]”

为了继续脚本,我需要让数组看起来像这样:

“[email1、email2、email3]”

所以只是没有外括号。我知道我可以通过在“.getValues()”后面添加“[0]”来定位“[email1]”。我尝试了诸如“[[all]]”之类的东西,但没有用。我需要改变什么?我知道,这可能是非常基本的,但我绝对是初学者,感谢您的帮助。

function myFunction() {

  // Variables
  var id = "ID";
  var spreadSheet = SpreadsheetApp.openById(id);
  var inputSheet = spreadSheet.getSheetByName("inputSheet");
  var inputLR = inputSheet.getLastRow();
  var emailsAll = inputSheet.getRange(2, 3, inputLR).getValues();

  Logger.log(emailsAll);
}
Run Code Online (Sandbox Code Playgroud)

The*_*ter 7

V8 更新(ES6):

使用Array#flat

var em = emailsAll.flat();//[[e],[e],[e]]=>[e,e,e]
Run Code Online (Sandbox Code Playgroud)

尝试Array#mapArray#forEach

var em = emailsAll.map(function(e){return e[0];});//[[e],[e],[e]]=>[e,e,e]
Run Code Online (Sandbox Code Playgroud)