Class Properties
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
详细文档
deleteAllProperties()
删除当前 Properties
存储区中的所有媒体资源。
// Deletes all user properties.
const userProperties = PropertiesService.getUserProperties();
userProperties.deleteAllProperties();
返回
Properties
- 此 Properties
存储,用于链式调用
deleteProperty(key)
在当前 Properties
存储区中删除具有给定键的媒体资源。
// Deletes the user property 'nickname'.
const userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('nickname');
参数
名称 | 类型 | 说明 |
key | String | 要删除的媒体资源的键 |
返回
Properties
- 此 Properties
存储,用于链式调用
getKeys()
获取当前 Properties
存储区中的所有键。
// Sets several properties, then logs the value of each key.
const scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
cow: 'moo',
sheep: 'baa',
chicken: 'cluck',
});
const keys = scriptProperties.getKeys();
Logger.log('Animals known:');
for (let i = 0; i < keys.length; i++) {
Logger.log(keys[i]);
}
返回
String[]
- 当前 Properties
存储区中的所有键的数组
getProperties()
获取当前 Properties
存储区中所有键值对的副本。请注意,返回的对象不是商店的实时视图。因此,更改返回对象的属性不会自动更新存储空间中的属性,反之亦然。
// Sets several script properties, then retrieves them and logs them.
const scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
cow: 'moo',
sheep: 'baa',
chicken: 'cluck',
});
const animalSounds = scriptProperties.getProperties();
// Logs:
// A chicken goes cluck!
// A cow goes moo!
// A sheep goes baa!
for (const kind in animalSounds) {
Logger.log('A %s goes %s!', kind, animalSounds[kind]);
}
返回
Object
- 当前 Properties
存储区中所有键值对的副本
getProperty(key)
获取当前 Properties
存储区中与给定键关联的值,如果不存在此类键,则返回 null
。
// Gets the user property 'nickname'.
const userProperties = PropertiesService.getUserProperties();
const nickname = userProperties.getProperty('nickname');
Logger.log(nickname);
参数
名称 | 类型 | 说明 |
key | String | 要检索的属性值的键 |
返回
String
- 与当前 Properties
存储区中的给定键关联的值
setProperties(properties)
在当前 Properties
存储区中设置给定对象中的所有键值对。
// Sets multiple user properties at once.
const userProperties = PropertiesService.getUserProperties();
const newProperties = {
nickname: 'Bob',
region: 'US',
language: 'EN'
};
userProperties.setProperties(newProperties);
参数
名称 | 类型 | 说明 |
properties | Object | 一个包含要设置的键值对的对象 |
返回
Properties
- 此 Properties
存储,用于链式调用
setProperties(properties, deleteAllOthers)
在当前 Properties
存储区中设置给定对象中的所有键值对,并可选择删除存储区中的所有其他属性。
// Sets multiple user properties at once while deleting all other user
// properties.
const userProperties = PropertiesService.getUserProperties();
const newProperties = {
nickname: 'Bob',
region: 'US',
language: 'EN'
};
userProperties.setProperties(newProperties, true);
参数
名称 | 类型 | 说明 |
properties | Object | 一个包含要设置的键值对的对象 |
deleteAllOthers | Boolean | true 表示删除 properties 对象中的所有其他键值对;false 表示不删除 |
返回
Properties
- 此 Properties
存储,用于链式调用
setProperty(key, value)
在当前 Properties
存储区中设置给定键值对。
// Sets the user property 'nickname' to 'Bobby'.
const userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('nickname', 'Bobby');
参数
名称 | 类型 | 说明 |
key | String | 相应媒体资源的键 |
value | String | 要与键关联的值 |
返回
Properties
- 此 Properties
存储,用于链式调用
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe \u003ccode\u003eProperties\u003c/code\u003e object provides an interface to access user, document, or script properties based on the selected method from \u003ccode\u003ePropertiesService\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProperties are isolated to individual scripts and cannot be shared.\u003c/p\u003e\n"],["\u003cp\u003eThis service allows scripts to store and retrieve data persistently, offering methods for setting, getting, and deleting properties.\u003c/p\u003e\n"],["\u003cp\u003eIt's important to note that \u003ccode\u003egetProperties()\u003c/code\u003e returns a copy, so modifications won't directly affect the stored properties.\u003c/p\u003e\n"],["\u003cp\u003eMethods for bulk operations like \u003ccode\u003esetProperties()\u003c/code\u003e and \u003ccode\u003edeleteAllProperties()\u003c/code\u003e are available for efficiency.\u003c/p\u003e\n"]]],[],null,["# Class Properties\n\nProperties\n\nThe properties object acts as the interface to access user, document, or script properties. The\nspecific property type depends on which of the three methods of [PropertiesService](/apps-script/reference/properties/properties-service) the\nscript called: [PropertiesService.getDocumentProperties()](/apps-script/reference/properties/properties-service#getDocumentProperties()), [PropertiesService.getUserProperties()](/apps-script/reference/properties/properties-service#getUserProperties()), or [PropertiesService.getScriptProperties()](/apps-script/reference/properties/properties-service#getScriptProperties()).\nProperties cannot be shared between scripts. For more information about property types, see the\n[guide to the Properties service](/apps-script/guides/properties). \n\n### Methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------------------------|-----------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| [deleteAllProperties()](#deleteAllProperties()) | [Properties](#) | Deletes all properties in the current `Properties` store. |\n| [deleteProperty(key)](#deleteProperty(String)) | [Properties](#) | Deletes the property with the given key in the current `Properties` store. |\n| [getKeys()](#getKeys()) | `String[]` | Gets all keys in the current `Properties` store. |\n| [getProperties()](#getProperties()) | `Object` | Gets a copy of all key-value pairs in the current `Properties` store. |\n| [getProperty(key)](#getProperty(String)) | `String` | Gets the value associated with the given key in the current `Properties` store, or `null` if no such key exists. |\n| [setProperties(properties)](#setProperties(Object)) | [Properties](#) | Sets all key-value pairs from the given object in the current `Properties` store. |\n| [setProperties(properties, deleteAllOthers)](#setProperties(Object,Boolean)) | [Properties](#) | Sets all key-value pairs from the given object in the current `Properties` store, optionally deleting all other properties in the store. |\n| [setProperty(key, value)](#setProperty(String,String)) | [Properties](#) | Sets the given key-value pair in the current `Properties` store. |\n\nDetailed documentation\n----------------------\n\n### `delete``All``Properties()`\n\nDeletes all properties in the current `Properties` store.\n\n```javascript\n// Deletes all user properties.\nconst userProperties = PropertiesService.getUserProperties();\nuserProperties.deleteAllProperties();\n```\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `delete``Property(key)`\n\nDeletes the property with the given key in the current `Properties` store.\n\n```javascript\n// Deletes the user property 'nickname'.\nconst userProperties = PropertiesService.getUserProperties();\nuserProperties.deleteProperty('nickname');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|------------------------------------|\n| `key` | `String` | the key for the property to delete |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `get``Keys()`\n\nGets all keys in the current `Properties` store.\n\n```javascript\n// Sets several properties, then logs the value of each key.\nconst scriptProperties = PropertiesService.getScriptProperties();\nscriptProperties.setProperties({\n cow: 'moo',\n sheep: 'baa',\n chicken: 'cluck',\n});\nconst keys = scriptProperties.getKeys();\nLogger.log('Animals known:');\nfor (let i = 0; i \u003c keys.length; i++) {\n Logger.log(keys[i]);\n}\n```\n\n#### Return\n\n\n`String[]` --- an array of all keys in the current `Properties` store\n\n*** ** * ** ***\n\n### `get``Properties()`\n\nGets a copy of all key-value pairs in the current `Properties` store. Note that the\nreturned object is not a live view of the store. Consequently, changing the properties on the\nreturned object will not automatically update them in storage, or vice versa.\n\n```javascript\n// Sets several script properties, then retrieves them and logs them.\nconst scriptProperties = PropertiesService.getScriptProperties();\nscriptProperties.setProperties({\n cow: 'moo',\n sheep: 'baa',\n chicken: 'cluck',\n});\n\nconst animalSounds = scriptProperties.getProperties();\n\n// Logs:\n// A chicken goes cluck!\n// A cow goes moo!\n// A sheep goes baa!\nfor (const 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 all key-value pairs in the current `Properties` store\n\n*** ** * ** ***\n\n### `get``Property(key)`\n\nGets the value associated with the given key in the current `Properties` store, or `null` if no such key exists.\n\n```javascript\n// Gets the user property 'nickname'.\nconst userProperties = PropertiesService.getUserProperties();\nconst nickname = userProperties.getProperty('nickname');\nLogger.log(nickname);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|--------------------------------------------|\n| `key` | `String` | the key for the property value to retrieve |\n\n#### Return\n\n\n`String` --- the value associated with the given key in the current `Properties` store\n\n*** ** * ** ***\n\n### `set``Properties(properties)`\n\nSets all key-value pairs from the given object in the current `Properties` store.\n\n```javascript\n// Sets multiple user properties at once.\nconst userProperties = PropertiesService.getUserProperties();\nconst newProperties = {\n nickname: 'Bob',\n region: 'US',\n language: 'EN'\n};\nuserProperties.setProperties(newProperties);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|----------------------------------------------|\n| `properties` | `Object` | an object containing key-values pairs to set |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `set``Properties(properties, deleteAllOthers)`\n\nSets all key-value pairs from the given object in the current `Properties` store,\noptionally deleting all other properties in the store.\n\n```javascript\n// Sets multiple user properties at once while deleting all other user\n// properties.\nconst userProperties = PropertiesService.getUserProperties();\nconst newProperties = {\n nickname: 'Bob',\n region: 'US',\n language: 'EN'\n};\nuserProperties.setProperties(newProperties, true);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------------|-----------|-------------------------------------------------------------------------------------|\n| `properties` | `Object` | an object containing key-values pairs to set |\n| `delete``All``Others` | `Boolean` | `true` to delete all other key-value pairs in the properties object; `false` to not |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `set``Property(key, value)`\n\nSets the given key-value pair in the current `Properties` store.\n\n```javascript\n// Sets the user property 'nickname' to 'Bobby'.\nconst userProperties = PropertiesService.getUserProperties();\nuserProperties.setProperty('nickname', 'Bobby');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|-------------------------------------|\n| `key` | `String` | the key for the property |\n| `value` | `String` | the value to associate with the key |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining"]]