Class UserProperties
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
พร็อพเพอร์ตี้ผู้ใช้
เลิกใช้งานแล้ว คลาสนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่
พร็อพเพอร์ตี้ผู้ใช้คือคู่คีย์-ค่าที่ไม่ซ้ำกันสำหรับผู้ใช้แต่ละราย พร็อพเพอร์ตี้ผู้ใช้จะกำหนดขอบเขตตามผู้ใช้ สคริปต์ที่ทำงานภายใต้ข้อมูลประจำตัวของผู้ใช้จะเข้าถึงพร็อพเพอร์ตี้ผู้ใช้สำหรับผู้ใช้รายนั้นเท่านั้น
วิธีการที่เลิกใช้งาน
deleteAllProperties()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
ลบพร็อพเพอร์ตี้ทั้งหมด
UserProperties.deleteAllProperties();
รีเทิร์น
UserProperties
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
ดูเพิ่มเติม
deleteProperty(key)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
ลบพร็อพเพอร์ตี้ที่มีคีย์ที่ระบุ
UserProperties.deleteProperty('special');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
key | String | คีย์สําหรับพร็อพเพอร์ตี้ที่จะลบ |
รีเทิร์น
UserProperties
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
ดูเพิ่มเติม
getKeys()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
รับคีย์ที่ใช้ได้ทั้งหมด
รีเทิร์น
String[]
getProperties()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
รับพร็อพเพอร์ตี้ทั้งหมดที่ใช้ได้พร้อมกัน
ซึ่งจะให้สำเนา ไม่ใช่มุมมองแบบเรียลไทม์ ดังนั้นการเปลี่ยนแปลงพร็อพเพอร์ตี้ในออบเจ็กต์ที่แสดงผลจะไม่อัปเดตพร็อพเพอร์ตี้ในระบบพื้นที่เก็บข้อมูล และในทางกลับกัน
UserProperties.setProperties({
"cow" : "moo",
"sheep" : "baa",
"chicken" : "cluck"
});
// Logs "A cow goes: moo"
Logger.log("A cow goes: %s", UserProperties.getProperty("cow"));
// This makes a copy. Any changes that happen here will not
// be written back to properties.
var animalSounds = UserProperties.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 = UserProperties.getProperty('special');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
key | String | คีย์ของค่าที่จะดึงข้อมูล |
รีเทิร์น
String
— ค่าที่เชื่อมโยงกับคีย์
ดูเพิ่มเติม
setProperties(properties)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
ตั้งค่าพร็อพเพอร์ตี้ทั้งหมดที่ดึงมาจากออบเจ็กต์ที่ระบุพร้อมกัน
UserProperties.setProperties({special: 'sauce', 'meaning': 42});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
properties | Object | ออบเจ็กต์ที่มีพร็อพเพอร์ตี้ที่จะตั้งค่า |
รีเทิร์น
UserProperties
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
ดูเพิ่มเติม
setProperties(properties, deleteAllOthers)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
ตั้งค่าพร็อพเพอร์ตี้ทั้งหมดที่ดึงมาจากออบเจ็กต์ที่ระบุพร้อมกัน
// This deletes all other properties
UserProperties.setProperties({special: 'sauce', 'meaning': 42}, true);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
properties | Object | ออบเจ็กต์ที่มีพร็อพเพอร์ตี้ที่จะตั้งค่า |
deleteAllOthers | Boolean | ลบพร็อพเพอร์ตี้ที่มีอยู่ทั้งหมดหรือไม่ |
รีเทิร์น
UserProperties
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
ดูเพิ่มเติม
setProperty(key, value)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
เก็บค่า in ที่ระบุไว้ด้วยคีย์ที่ระบุ ระบบจะเขียนทับค่าที่มีอยู่ซึ่งเชื่อมโยงกับคีย์นี้
UserProperties.setProperty('special', 'sauce');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
key | String | คีย์สําหรับพร็อพเพอร์ตี้ |
value | String | ค่าที่จะเชื่อมโยงกับคีย์ |
รีเทิร์น
UserProperties
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
ดูเพิ่มเติม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eUserProperties\u003c/code\u003e is deprecated and should not be used in new scripts.\u003c/p\u003e\n"],["\u003cp\u003eUser Properties are key-value pairs unique to a user, accessible only by scripts running under that user's identity.\u003c/p\u003e\n"],["\u003cp\u003eAll methods within \u003ccode\u003eUserProperties\u003c/code\u003e are deprecated, including those for setting, getting, and deleting properties.\u003c/p\u003e\n"],["\u003cp\u003eDespite being deprecated, \u003ccode\u003eUserProperties\u003c/code\u003e provides functionalities like \u003ccode\u003egetProperties()\u003c/code\u003e which returns a copy of the properties, and \u003ccode\u003edeleteAllProperties()\u003c/code\u003e to remove all properties.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should avoid using \u003ccode\u003eUserProperties\u003c/code\u003e and explore alternative solutions for managing user-specific data in new scripts.\u003c/p\u003e\n"]]],[],null,["# Class UserProperties\n\nUserProperties\n\n\n**Deprecated.** This class is deprecated and should not be used in new scripts.\n\nUser Properties are key-value pairs unique to a user. User Properties are scoped per user; any\nscript running under the identity of a user can access User Properties for that user only. \n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------------------------|---------------------|----------------------------------------------------------------------------------------|\n| [deleteAllProperties()](#deleteAllProperties()) | [UserProperties](#) | Deletes all properties. |\n| [deleteProperty(key)](#deleteProperty(String)) | [UserProperties](#) | 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)) | [UserProperties](#) | Bulk-sets all the properties drawn from the given object. |\n| [setProperties(properties, deleteAllOthers)](#setProperties(Object,Boolean)) | [UserProperties](#) | Bulk-sets all the properties drawn from the given object. |\n| [setProperty(key, value)](#setProperty(String,String)) | [UserProperties](#) | 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\nUserProperties.deleteAllProperties();\n```\n\n#### Return\n\n\n[UserProperties](#) --- 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\nUserProperties.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[UserProperties](#) --- 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\nUserProperties.setProperties({\n \"cow\" : \"moo\",\n \"sheep\" : \"baa\",\n \"chicken\" : \"cluck\"\n});\n\n// Logs \"A cow goes: moo\"\nLogger.log(\"A cow goes: %s\", UserProperties.getProperty(\"cow\"));\n\n// This makes a copy. Any changes that happen here will not\n// be written back to properties.\nvar animalSounds = UserProperties.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 = UserProperties.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\nUserProperties.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[UserProperties](#) --- 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\nUserProperties.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[UserProperties](#) --- 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\nUserProperties.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[UserProperties](#) --- this object, for chaining\n\n#### See also\n\n- [getProperty(key)](#getProperty(String))"]]