Is there an "easy" way of converting a GAS string array (in .gs file) to a javascript array that exists in an HTML file? I'm trying to use jquery to do stuff, and it requires (from what I can tell) values to be in a javascript array. The first piece of code is the function that gets email addresses from contacts app and returns an array of strings. The rest are samples of HTML with a link break to separate their cajoled result (at least I'm pretty sure their cajoled result). Also, this is basically what I'm using the availableTags variable for you'll see below: http://jqueryui.com/autocomplete/
Script File, returns a string array of email addresses
function getAllContacts(){
var contacts = ContactsApp.getContactsByGroup(ContactsApp.getContactGroup("ContactsAppTest"));
var email = new Array();
for(var i=0;i<contacts.length;i++){
if(contacts[i].getPrimaryEmail() != ""){
email.push(contacts[i].getPrimaryEmail());
}
}
return email;
}
Try 1, create an empty js array, and manually populate from getAllContacts function. This works, but thinking this is not very efficient.
var availableTags = [];
<?
var temp = getAllContacts();
for (var i=0; i<temp.length; i++) { ?>
availableTags.push(<?= temp[i] ?>);
<?} ?>
availableTags.push_m___?availableTags.push('[email protected]'):availableTags.m___('push',['[email protected]']);availableTags.push_m___?availableTags.push('[email protected]'):availableTags.m___('push',['[email protected]']);availableTags.push_m___?availableTags.push('[email protected]'):availableTags.m___('push',['[email protected]']);
Try 2, set availableTags = getAllContacts function
var availableTags = <?=getAllContacts()?>;
availableTags='[email protected],[email protected],[email protected]'
Normal js array
var availableTags = ["[email protected]","[email protected]","[email protected]"];
availableTags=['[email protected]','[email protected]','[email protected]'];