0

I am trying to create an array or map linking 3 different sets of values using Google App Script. My three sets of values can be denoted as A, B, and C. I am thinking of using A as a key linking to a pair of values {B, C}. How do you implement this in Google App Script? Is there a better way to do this? Thank you for the help!

7
  • Please checkout developers.google.com/apps-script Commented Jun 22, 2018 at 21:05
  • @Rubén I've looked through Google Apps Script documentation, but I can't find anything similar to Key-Value pairs found in C++ and Java. Commented Jun 22, 2018 at 21:07
  • 3
    Google Apps Script is basically Javascript so you can use objects to create key-value pairs. Read this: developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/… Commented Jun 22, 2018 at 21:30
  • 1
    As mentioned in the previous comment by Dimu Designs, Google Apps Script use JavaScript. The introduction mention that and suggest to learn about JavaScript even mention an online course. By the other hand if we search key value on the Google Apps Script site, there are a lot of results that include those terms. Commented Jun 23, 2018 at 1:13
  • @Rubén I think this is a perfectly valid question. Is there a known structure in scripts that can hold key-value pairs? Referencing the whole documentation is zero help. In Java and C# that would be dictionaries and maps. Javascript supports named arrays, but maybe there is something more specific in Scripts. Commented Apr 28, 2019 at 18:50

1 Answer 1

1

Here is my implementation:

var data = sheet.getDataRange().getValues();    

var basic_details = {
   "roll_number":data[12][2],
   "first_name":data[13][2],
   "last_name":data[14][2],
   "gender":data[15][2],
   "type":data[16][2]
};    

var all_data = {
"search_for" : search_roll_num , 
"basic_details" : basic_details , 
};

var access_last_name = all_data.basic_details.last_name;

Here I am able to refer to values by their key name. Maybe this helps?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.