array.join(separator)
array.join(separator)join returns a string value consisting of all the elements of an array concatenated and separated by the specified separator character. If separator is omitted, the array elements are separated with a comma. If any element of the array is undefined or null, it is treated as an empty string ("").
array.toString()
array.valueOf()
Both toString and valueOf converts elements of an array to strings. The resulting strings are concatenated, separated by commas. This is the same as using join without specifying a separator (or specifying comma as separator).
Converting an Array to a String with Line Breaks between Elements
This example is similar to using categoryLabels to list the answers to a multi question and include them in an email text (go to String Object Methods that Use Regular Expression Objects for more information). Instead of the default commas between the items listed in the array returned from categoryLabels, we want line breaks. If the email is sent as plain text, you then have to replace the commas with the special character \n.
This script will convert the array to a string and use line breaks as delimiter between the elements of a multi question brands:
var body = "";
body += "Here are the answers on the brands question:\n\n"
var brandsAnswers = f("brands").categoryLabels();
brandsAnswers = brandsAnswers.join("\n");
body += brandsAnswers
SendMail("interviewer@forsta.com",f("email"),"Answers",body);
If the mail is sent as HTML, you must replace the commas with the HTML <br> tag:
var body = "";
body += "Here are the answers on the brands question:<br><br>"
var brandsAnswers = f("brands").categoryLabels();
brandsAnswers = brandsAnswers.join("<br>");
body += brandsAnswers
SendMail("interviewer@forsta.com",f("email"),"Answers",body,"","",0,0);