HTMLOptionsCollection: remove() method

Phương thức remove() của giao diện HTMLOptionsCollection xóa phần tử <option> được chỉ định bởi chỉ số khỏi tập hợp này.

Cú pháp

js
remove(index)

Tham số

index

Một số nguyên bắt đầu từ 0 cho chỉ số của HTMLOptionElement trong HTMLOptionsCollection. Nếu chỉ số không được tìm thấy, phương thức không có hiệu lực.

Giá trị trả về

Không có (undefined).

Ví dụ

js
const optionList = document.querySelector("select").options;
const listLength = optionList.length;
optionList.remove(listLength - 1); // removes the last item
optionList.remove(0); // removes the first item

Thông số kỹ thuật

Specification
HTML
# dom-htmloptionscollection-remove-dev

Tương thích trình duyệt

Xem thêm