Google Apps Script e.namedValues format multiple c

2019-02-26 10:25发布

I have a simple script that emails the results of a Google Drive form submission. One of the questions in the form has multiple choice checkboxes. I am using e.namedValues to grab the array of answers so that I can email them, like this:

var multiple = e.namedValues['Multiple Choice Question'].toString();

And the result that gets emailed is this:

Answer 1, Answer 2, Answer 3

But I would like the result to be formatted like this:

Answer 1
Answer 2
Answer 3

Instead of separated by commas. Is there any way to do this?

1条回答
可以哭但决不认输i
2楼-- · 2019-02-26 10:42

Use JavaScript String's split function

var multiple = e.namedValues['Multiple Choice Question'].toString();
var choicesSelected = multiple.split(',');
multiple =''; 
for(var i in choicesSelected){
  multiple += choicesSelected[i] + '\n' ;
}
for (var i in multiple){
  Logger.log(multiple[i]);
}
查看更多
登录 后发表回答