在Google Apps脚本中迭代对象 [英] Iterate over an object in Google Apps script
本文介绍了在Google Apps脚本中迭代对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为我的问题可以通过此或此,但不是是我正在寻找的。 p>
我在Google Script中有一个对象,并且想遍历每个元素:
var dict = {
foo:a,
bar:b
};
为每个键,元素在字典{
打印键和元素
}
这可能吗?
解决方案
我通常会这样做:
var dict = {
foo:a,
bar:b
};
function showProperties(){
var keys = [];
for(var k in dict)keys.push(k +':'+ dict [k]);
Logger.log(total+ keys.length +\\\
+ keys.join('\\\
'));
}
结果记录器:
你会得到记录器位于脚本编辑器/视图/日志
中
I thought my question would be answered with this or this but neither is what I'm looking for.
I have an object in Google Script, and want to iterate over each element:
var dict = {
"foo": "a",
"bar": "b"
};
for each key, element in dict{
print the key and the element
}
Is this possible?
解决方案
I usually do something like that :
var dict = {
"foo": "a",
"bar": "b"
};
function showProperties(){
var keys = [];
for(var k in dict) keys.push(k+':'+dict[k]);
Logger.log("total " + keys.length + "\n" + keys.join('\n'));
}
result in Logger :
You get the logger in the script editor/view/Logs
这篇关于在Google Apps脚本中迭代对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文