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!
Asked
Active
Viewed 7,747 times
0
-
Please checkout https://developers.google.com/apps-script – Rubén Jun 22 '18 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. – Eric Jun 22 '18 at 21:07
-
3Google Apps Script is basically Javascript so you can use objects to create key-value pairs. Read this: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics – TheAddonDepot Jun 22 '18 at 21:30
-
1As 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. – Rubén Jun 23 '18 at 01: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. – Odys Apr 28 '19 at 18:50
-
@Odys The title could be good but the body of the question isn't as it doesn't show any search/research effort. If you already made a search/research effort I suggest you to post a new question or if you already know the answer please add it. – Rubén Apr 28 '19 at 18:58
-
Also this question is unclear as it doesn't mention how the sets of values are handled. Anyway, this might help: [How can I add a key/value pair to a JavaScript object?](https://stackoverflow.com/q/1168807/1595451), [How to create dictionary and add key–value pairs dynamically?](https://stackoverflow.com/q/7196212/1595451) – Rubén Apr 28 '19 at 19:09
1 Answers
0
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?

Tanveer Chandok
- 51
- 2