Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Starting 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-05 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,["Starting 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\nCode 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\nColab (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```"]]