Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting the value of key/value pair in Google App Script

I have two files in an App Script project:

#Code.gs
function myFunction() {
  ksu = "Kansas State University";
  Logger.log(lgu_map[ksu]);
}

#data.gs
function lgu_map() {
  map["University of Arkansas Pine Bluff"] = "1890";
  map["University of Maryland Eastern Shore"] = "1890";
  map["Virginia State University"] = "1890";
  map["West Virginia State University"] = "1890";
  map["Iowa State University"] = "North Central";
  map["Kansas State University"] = "North Central";
  map["Michigan State University"] = "North Central";
  map["North Dakota State University"] = "North Central";
  map["Ohio State University    North"] = "Central";
}

What I am wanting to do is query the lgu_map() function in data.gs to return is value. So in this case, what I’m wanting Logger.log(lgu_map[ksu]); to return is North Central.

Not even sure if I can call the function with way without actually passing an argument.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help appreciated

>Solution :

Try it this way:

const myMap = new Map();
myMap.set("University of Arkansas Pine Bluff", "1890");
myMap.set("University of Maryland Eastern Shore", "1890");
myMap.set("Virginia State University", "1890");
myMap.set("West Virginia State University", "1890");
myMap.set("Iowa State University", "North Central");
myMap.set("Kansas State University", "North Central");
myMap.set("Michigan State University", "North Central");
myMap.set("North Dakota State University", "North Central");
myMap.set("Ohio State University    North", "Central");
myMap.get("University of Arkansas Pine Bluff");//1890
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading