ee.List.splice

Bắt đầu từ chỉ mục bắt đầu, xoá các phần tử đếm khỏi danh sách và chèn nội dung của phần tử khác vào vị trí đó. Nếu start là số âm, thì hàm sẽ đếm ngược từ cuối danh sách.

Cách sử dụngGiá trị trả về
List.splice(start, count, other)Danh sách
Đối sốLoạiThông tin chi tiết
this: listDanh sách
startSố nguyên
countSố nguyên
otherDanh sách, mặc định: null

Ví dụ

Trình soạn thảo mã (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']));

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

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())