[英]How do I use an array as a key in a Google Apps Scripts dictionary and have it maintain its array structure while I iterate over the dictionary
Why do the square brackets of the array get taken away when I use the array as a key?当我使用数组作为键时,为什么数组的方括号会被拿走? Looking at this function and the output vs expected output, how do I make sure the key is actually an array and that I can index it as such?
查看此函数和输出与预期输出,我如何确保键实际上是一个数组并且我可以这样索引它?
function functionName() {
d = {};
a = [3, 3];
d[a] = 100;
Logger.log(d);
//output: {3,3=100.0}
//expected output: {[3,3]=100.0}
for (var key in d){
Logger.log(key);
//output: 3,3
//expected output: [3, 3]
Logger.log(d[key]);
//output: 100.0
//I would like to be able to say
//index1 = key[0];
//index2 = key[1];
//where index1 and index2 will evaluate to 3
//but this throws an error
}
}
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.