Class ScriptProperties
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Script 屬性
已淘汰。這個類別已淘汰,不應在新的指令碼中使用。
指令碼屬性是指令碼在永久儲存區中儲存的鍵/值組合。無論是哪位使用者執行指令碼,每個指令碼的範圍都會是指令碼本身。
已淘汰的方法
deleteAllProperties()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
刪除所有資源。
ScriptProperties.deleteAllProperties();
回攻員
ScriptProperties
:這個物件,用於鏈結
另請參閱
deleteProperty(key)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
刪除指定鍵的屬性。
ScriptProperties.deleteProperty('special');
參數
回攻員
ScriptProperties
:這個物件,用於鏈結
另請參閱
getKeys()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得所有可用的鍵。
回攻員
String[]
getProperties()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
一次取得所有可用的資源。
這會提供副本,而非即時檢視畫面,因此變更已回傳物件的屬性不會更新儲存空間中的屬性,反之亦然。
ScriptProperties.setProperties({
"cow" : "moo",
"sheep" : "baa",
"chicken" : "cluck"
});
// Logs "A cow goes: moo"
Logger.log("A cow goes: %s", ScriptProperties.getProperty("cow"));
// This makes a copy. Any changes that happen here will not
// be written back to properties.
var animalSounds = ScriptProperties.getProperties();
// Logs:
// A chicken goes cluck!
// A cow goes moo!
// A sheep goes baa!
for(var kind in animalSounds) {
Logger.log("A %s goes %s!", kind, animalSounds[kind]);
}
回攻員
Object
:包含鍵/值組合的屬性副本
getProperty(key)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
傳回與提供的鍵相關聯的值,如果沒有此類值,則傳回空值。
const specialValue = ScriptProperties.getProperty('special');
參數
回攻員
String
:與鍵相關聯的值
另請參閱
setProperties(properties)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
大量設定從指定物件繪製的所有屬性。
ScriptProperties.setProperties({special: 'sauce', 'meaning': 42});
參數
名稱 | 類型 | 說明 |
properties | Object | 包含要設定的屬性的物件。 |
回攻員
ScriptProperties
:這個物件,用於鏈結
另請參閱
setProperties(properties, deleteAllOthers)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
大量設定從指定物件繪製的所有屬性。
// This deletes all other properties
ScriptProperties.setProperties({special: 'sauce', 'meaning': 42}, true);
參數
名稱 | 類型 | 說明 |
properties | Object | 包含要設定的屬性的物件。 |
deleteAllOthers | Boolean | 是否要刪除所有現有資源。 |
回攻員
ScriptProperties
:這個物件,用於鏈結
另請參閱
setProperty(key, value)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
使用提供的鍵將指定的值儲存。系統會覆寫與此鍵相關聯的任何現有值。
ScriptProperties.setProperty('special', 'sauce');
參數
名稱 | 類型 | 說明 |
key | String | 屬性鍵 |
value | String | 要與鍵建立關聯的值 |
回攻員
ScriptProperties
:這個物件,用於鏈結
另請參閱
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eScriptProperties is deprecated and should not be used in new scripts, serving as a persistent key-value store scoped per script.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for setting, getting, and deleting properties, but these are all deprecated.\u003c/p\u003e\n"],["\u003cp\u003eDespite offering functionalities like bulk operations and property retrieval, developers should refrain from using them in new projects.\u003c/p\u003e\n"],["\u003cp\u003eThe class is primarily for legacy scripts and should be replaced with more modern alternatives for data persistence.\u003c/p\u003e\n"]]],[],null,["# Class ScriptProperties\n\nScriptProperties\n\n\n**Deprecated.** This class is deprecated and should not be used in new scripts.\n\nScript Properties are key-value pairs stored by a script in a persistent store. Script Properties\nare scoped per script, regardless of which user runs the script. \n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------------------------|-----------------------|----------------------------------------------------------------------------------------|\n| [deleteAllProperties()](#deleteAllProperties()) | [ScriptProperties](#) | Deletes all properties. |\n| [deleteProperty(key)](#deleteProperty(String)) | [ScriptProperties](#) | Deletes the property with the given key. |\n| [getKeys()](#getKeys()) | `String[]` | Get all of the available keys. |\n| [getProperties()](#getProperties()) | `Object` | Get all of the available properties at once. |\n| [getProperty(key)](#getProperty(String)) | `String` | Returns the value associated with the provided key, or null if there is no such value. |\n| [setProperties(properties)](#setProperties(Object)) | [ScriptProperties](#) | Bulk-sets all the properties drawn from the given object. |\n| [setProperties(properties, deleteAllOthers)](#setProperties(Object,Boolean)) | [ScriptProperties](#) | Bulk-sets all the properties drawn from the given object. |\n| [setProperty(key, value)](#setProperty(String,String)) | [ScriptProperties](#) | Persists the specified in value with the provided key. |\n\nDeprecated methods\n------------------\n\n### `delete``All``Properties()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes all properties.\n\n```javascript\nScriptProperties.deleteAllProperties();\n```\n\n#### Return\n\n\n[ScriptProperties](#) --- this object, for chaining\n\n#### See also\n\n- [deleteProperty(key)](#deleteProperty(String))\n\n*** ** * ** ***\n\n### `delete``Property(key)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes the property with the given key.\n\n```javascript\nScriptProperties.deleteProperty('special');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|----------------------------|\n| `key` | `String` | key for property to delete |\n\n#### Return\n\n\n[ScriptProperties](#) --- this object, for chaining\n\n#### See also\n\n- [deleteAllProperties()](#deleteAllProperties())\n\n*** ** * ** ***\n\n### `get``Keys()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGet all of the available keys.\n\n#### Return\n\n\n`String[]`\n\n*** ** * ** ***\n\n### `get``Properties()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGet all of the available properties at once.\n\nThis gives a copy, not a live view, so changing the properties on the returned object won't\nupdate them in storage and vice versa.\n\n```javascript\nScriptProperties.setProperties({\n \"cow\" : \"moo\",\n \"sheep\" : \"baa\",\n \"chicken\" : \"cluck\"\n});\n\n// Logs \"A cow goes: moo\"\nLogger.log(\"A cow goes: %s\", ScriptProperties.getProperty(\"cow\"));\n\n// This makes a copy. Any changes that happen here will not\n// be written back to properties.\nvar animalSounds = ScriptProperties.getProperties();\n\n// Logs:\n// A chicken goes cluck!\n// A cow goes moo!\n// A sheep goes baa!\nfor(var kind in animalSounds) {\n Logger.log(\"A %s goes %s!\", kind, animalSounds[kind]);\n}\n```\n\n#### Return\n\n\n`Object` --- a copy of the properties containing key-value pairs\n\n*** ** * ** ***\n\n### `get``Property(key)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nReturns the value associated with the provided key, or null if there is no such value.\n\n```javascript\nconst specialValue = ScriptProperties.getProperty('special');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|-------------------------------|\n| `key` | `String` | key for the value to retrieve |\n\n#### Return\n\n\n`String` --- the value associated with the key\n\n#### See also\n\n- [setProperty(key, value)](#setProperty(String,String))\n\n*** ** * ** ***\n\n### `set``Properties(properties)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nBulk-sets all the properties drawn from the given object.\n\n```javascript\nScriptProperties.setProperties({special: 'sauce', 'meaning': 42});\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|---------------------------------------------|\n| `properties` | `Object` | an object containing the properties to set. |\n\n#### Return\n\n\n[ScriptProperties](#) --- this object, for chaining\n\n#### See also\n\n- [setProperty(key, value)](#setProperty(String,String))\n\n*** ** * ** ***\n\n### `set``Properties(properties, deleteAllOthers)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nBulk-sets all the properties drawn from the given object.\n\n```javascript\n// This deletes all other properties\nScriptProperties.setProperties({special: 'sauce', 'meaning': 42}, true);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------------|-----------|---------------------------------------------|\n| `properties` | `Object` | an object containing the properties to set. |\n| `delete``All``Others` | `Boolean` | whether to delete all existing properties. |\n\n#### Return\n\n\n[ScriptProperties](#) --- this object, for chaining\n\n#### See also\n\n- [setProperty(key, value)](#setProperty(String,String))\n\n*** ** * ** ***\n\n### `set``Property(key, value)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nPersists the specified in value with the provided key. Any existing value associated with this\nkey will be overwritten.\n\n```javascript\nScriptProperties.setProperty('special', 'sauce');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|---------------------------------|\n| `key` | `String` | key for property |\n| `value` | `String` | value to associate with the key |\n\n#### Return\n\n\n[ScriptProperties](#) --- this object, for chaining\n\n#### See also\n\n- [getProperty(key)](#getProperty(String))"]]