Iterate over an object in Google Apps script

前端 未结 2 1094
一向
一向 2021-01-12 03:03

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 elem

相关标签:
2条回答
  • 2021-01-12 03:38

    With V8 runtime:

    var dict = {
      "foo": "a",
      "bar": "b"
    };
    
    for (const [key, value] of Object.entries(dict)) {
      Logger.log(`${key}: ${value}`);
    }

    0 讨论(0)
  • 2021-01-12 03:57

    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 image description here

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

    0 讨论(0)
提交回复
热议问题