ee.List.splice
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เริ่มจากดัชนีเริ่มต้น ให้นำองค์ประกอบจำนวนหนึ่งออกจากรายการและแทรกเนื้อหาขององค์ประกอบอื่นๆ ณ ตำแหน่งนั้น หาก start เป็นค่าลบ ระบบจะนับถอยหลังจากท้ายรายการ
การใช้งาน | การคืนสินค้า |
---|
List.splice(start, count, other) | รายการ |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
ดังนี้ list | รายการ | |
start | จำนวนเต็ม | |
count | จำนวนเต็ม | |
other | รายการ (ค่าเริ่มต้น: null) | |
ตัวอย่าง
โปรแกรมแก้ไขโค้ด (JavaScript)
// An ee.List object.
var list = ee.List([0, 1, 2, 3, 4]);
print('Original list', list);
// If "other" argument is null, elements at positions specified by "start" and
// "count" are deleted. Here, the 3rd element is removed.
print('Remove 1 element', list.splice({start: 2, count: 1, other: null}));
// If "start" is negative, the position is from the end of the list.
print('Remove 2nd from last element', list.splice(-2, 1));
// Deletes 3 elements starting at position 1.
print('Remove multiple sequential elements', list.splice(1, 3));
// Insert elements from the "other" list without deleting existing elements
// by specifying the insert "start" position and setting "count" to 0.
print('Insert new elements', list.splice(2, 0, ['X', 'Y', 'Z']));
// Replace existing elements with those from the "other" list by specifying the
// "start" position to replace and the "count" of proceeding elements. If
// length of "other" list is greater than "count", the remaining "other"
// elements are inserted, they do not replace existing elements.
print('Replace elements', list.splice(2, 3, ['X', 'Y', 'Z']));
การตั้งค่า Python
ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap
เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า
สภาพแวดล้อม Python
import ee
import geemap.core as geemap
Colab (Python)
# An ee.List object.
ee_list = ee.List([0, 1, 2, 3, 4])
print('Original list:', ee_list.getInfo())
# If "other" argument is None, elements at positions specified by "start" and
# "count" are deleted. Here, the 3rd element is removed.
print('Remove 1 element:',
ee_list.splice(start=2, count=1, other=None).getInfo())
# If "start" is negative, the position is from the end of the list.
print('Remove 2nd from last element:', ee_list.splice(-2, 1).getInfo())
# Deletes 3 elements starting at position 1.
print('Remove multiple sequential elements:', ee_list.splice(1, 3).getInfo())
# Insert elements from the "other" list without deleting existing elements
# by specifying the insert "start" position and setting "count" to 0.
print('Insert new elements:', ee_list.splice(2, 0, ['X', 'Y', 'Z']).getInfo())
# Replace existing elements with those from the "other" list by specifying the
# "start" position to replace and the "count" of proceeding elements. If
# length of "other" list is greater than "count", the remaining "other"
# elements are inserted, they do not replace existing elements.
print('Replace elements:', ee_list.splice(2, 3, ['X', 'Y', 'Z']).getInfo())
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eList.splice()\u003c/code\u003e modifies a list by removing elements and inserting new ones at a specified position.\u003c/p\u003e\n"],["\u003cp\u003eIt takes \u003ccode\u003estart\u003c/code\u003e, \u003ccode\u003ecount\u003c/code\u003e, and \u003ccode\u003eother\u003c/code\u003e as arguments to control the modification process.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estart\u003c/code\u003e determines the starting position for removal/insertion, while \u003ccode\u003ecount\u003c/code\u003e determines the number of elements to remove.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eother\u003c/code\u003e provides the elements to insert; if \u003ccode\u003eother\u003c/code\u003e is null or None, elements are only removed.\u003c/p\u003e\n"],["\u003cp\u003eA negative \u003ccode\u003estart\u003c/code\u003e value counts backwards from the end of the list for positioning.\u003c/p\u003e\n"]]],[],null,["# ee.List.splice\n\nStarting at the start index, removes count elements from list and insert the contents of other at that location. If start is negative, it counts backwards from the end of the list.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------|---------|\n| List.splice`(start, count, `*other*`)` | List |\n\n| Argument | Type | Details |\n|--------------|---------------------|---------|\n| this: `list` | List | |\n| `start` | Integer | |\n| `count` | Integer | |\n| `other` | List, default: null | |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// An ee.List object.\nvar list = ee.List([0, 1, 2, 3, 4]);\nprint('Original list', list);\n\n// If \"other\" argument is null, elements at positions specified by \"start\" and\n// \"count\" are deleted. Here, the 3rd element is removed.\nprint('Remove 1 element', list.splice({start: 2, count: 1, other: null}));\n\n// If \"start\" is negative, the position is from the end of the list.\nprint('Remove 2nd from last element', list.splice(-2, 1));\n\n// Deletes 3 elements starting at position 1.\nprint('Remove multiple sequential elements', list.splice(1, 3));\n\n// Insert elements from the \"other\" list without deleting existing elements\n// by specifying the insert \"start\" position and setting \"count\" to 0.\nprint('Insert new elements', list.splice(2, 0, ['X', 'Y', 'Z']));\n\n// Replace existing elements with those from the \"other\" list by specifying the\n// \"start\" position to replace and the \"count\" of proceeding elements. If\n// length of \"other\" list is greater than \"count\", the remaining \"other\"\n// elements are inserted, they do not replace existing elements.\nprint('Replace elements', list.splice(2, 3, ['X', 'Y', 'Z']));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# An ee.List object.\nee_list = ee.List([0, 1, 2, 3, 4])\nprint('Original list:', ee_list.getInfo())\n\n# If \"other\" argument is None, elements at positions specified by \"start\" and\n# \"count\" are deleted. Here, the 3rd element is removed.\nprint('Remove 1 element:',\n ee_list.splice(start=2, count=1, other=None).getInfo())\n\n# If \"start\" is negative, the position is from the end of the list.\nprint('Remove 2nd from last element:', ee_list.splice(-2, 1).getInfo())\n\n# Deletes 3 elements starting at position 1.\nprint('Remove multiple sequential elements:', ee_list.splice(1, 3).getInfo())\n\n# Insert elements from the \"other\" list without deleting existing elements\n# by specifying the insert \"start\" position and setting \"count\" to 0.\nprint('Insert new elements:', ee_list.splice(2, 0, ['X', 'Y', 'Z']).getInfo())\n\n# Replace existing elements with those from the \"other\" list by specifying the\n# \"start\" position to replace and the \"count\" of proceeding elements. If\n# length of \"other\" list is greater than \"count\", the remaining \"other\"\n# elements are inserted, they do not replace existing elements.\nprint('Replace elements:', ee_list.splice(2, 3, ['X', 'Y', 'Z']).getInfo())\n```"]]