Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:55:18+00:00 2026-06-14T07:55:18+00:00

Is there an easy way of converting a GAS string array (in .gs file)

  • 0

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('email1@test.com'):availableTags.m___('push',['email1@test.com']);availableTags.push_m___?availableTags.push('email2@test2.com'):availableTags.m___('push',['email2@test2.com']);availableTags.push_m___?availableTags.push('email3@test3.com'):availableTags.m___('push',['email3@test3.com']);

Try 2, set availableTags = getAllContacts function

var availableTags = <?=getAllContacts()?>;

availableTags='email1@test.com,email2@test2.com,email3@test3.com'

Normal js array

var availableTags = ["email1@test.com","email2@test2.com","email3@test3.com"];

availableTags=['email1@test.com','email2@test2.com','email3@test3.com'];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:55:19+00:00Added an answer on June 14, 2026 at 7:55 am

    Try something like this out:

    <? var temp = getAllContacts(); ?>
    var availableTags = <?= temp ? "[" + temp.toString() + "]" : "null" ?>;
    

    That should initialize the array on the client side all-at-once. (I wouldn’t worry too much about efficiency anyway, unless you’re dealing with hundred or thousands of these contacts. Myself, I’d shoot for what I found most readable.)

    UPDATE: as noted in comment, this won’t work, as the result appears to be enquoted.
    Other efforts to use new Function() or eval() on that string fail, likely due to the Caja sanitizer GAS uses on output. This should work, instead:

      <? var temp = getAllContacts(); ?>
    
      var array = null;
      var str  = <?= temp ? temp.toString() : "" ?>;
      if(str) array = str.split(",");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any easy way of converting a windows-1252 string into a Unicode one?
Is there an easy way in javascript to only escape certain ranges of control
Is there an easy way to calculate the derivative of non-liner functions that are
Is there an easy way to use UIElement.Effect in WPF to shift the color
Is there any easy way to check if one array contains another array in
Is there an easy way of converting a Actionscript 3 project to a Flex
Is there an easy way to log PHP errors to a log for a
Is there an easy way to generate docs for REST api direct from a
Is there an easy way of getting the datetime of the last change to
Is there an easy way to remove the character at a certain position in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.