Monday, June 3, 2024
101
rated 0 times [  104] [ 3]  / answers: 1 / hits: 31885  / 10 Years ago, mon, september 8, 2014, 12:00:00

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?


More From » google-apps-script

 Answers
195

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 :


enter


You get the logger in the script editor/view/Logs


[#69534] Friday, September 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eliezerc

Total Points: 286
Total Questions: 102
Total Answers: 102

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
eliezerc questions
Mon, Jun 20, 22, 00:00, 2 Years ago
Fri, Sep 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;