How to append to an object with Google Apps Script Editor

时间:2018-02-01 18:37:46

标签: object google-apps-script google-api append google-apps-script-editor

This is in Google Script Editor. I've done a lot of searching but for some reason I can't find any information about a simple thing such as appending to an object.

I have an object like this:

var get_options = {
    'method': 'get',
    'muteHttpExceptions': true,
};

How would I go about appending to that object?

I want to add 'authorization': 'token', to that object so the object will look like this:

var get_options = {
    'method': 'get',
    'muteHttpExceptions': true,
    'authorization': 'token',
};

Please help! Thank you in advance.

1 个答案:

答案 0 :(得分:4)

Google App Script(GAS)使用javascript平台。因此,只要您想要查找某些基本编码语法,请参阅javascript documentation

要简要回答您的问题,要将密钥对值添加到get_options,您可以执行以下操作

var get_options = {
    'method': 'get',
    'muteHttpExceptions': true,
};
 get_options.authorization = “token”
//or
get_options["authorization"] = “token”

您可以在此SO post

中找到更详细的说明