I literally cannot create a Map with keys and values in GAS.
function test() {
var a = new Map([['foo','bar']]);
console.log(a);
var b = new Map();
b.set('foo', 'bar');
console.log(b);
}
running the function outputs:
{}
{}
The only thread I found that is relevant is Map object support in Google Apps Script
I have already enabled running in Chrome V8 runtime.
Link to my GAS project: https://script.google.com/d/1o6ZhubxJ8Xj_F3EhmzYCzrULMQX-7zqeSEc83Cqzpcx7sswng8KWclTl/edit?usp=sharing
Please. Someone. Help me. What is going on...
EDIT: THE PLOT THICKENS
I can .get() the values, and .size shows me that the Map is actually increasing in size. But .keys(), .values() and .entries() return nothing in the console. But Array.from(b.entries()) does return an array of entries. Wtf is this?
After checking your code I was able to see that you are trying to print the keys, values, and entries methods directly by using:
console.log(b.keys());
console.log(b.values());
console.log(b.entries());
This is not possible because what you get in return from all of them is an iterator object and not an actual value, so first you need a way to show the values from that iterator, and that is why using Array.from() works correctly. So this is actually not a Google Apps Script issue but how Javascript works.
As an example you could also use something like:
console.log(b.keys().next().value);
console.log(b.entries().next().value);
console.log(b.values().next().value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With