HTML DOM
The remove() method of the HTMLOptionsCollection interface removes the option element specified by the index from this collection.
Syntax
remove(index)
Parameters
index- : A zero-based integer for the index of the HTMLOptionElement in the HTMLOptionsCollection. If the index is not found the method has no effect.
Return value
None (undefined).
Examples
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
Specifications
Browser compatibility
See also
- HTMLOptionsCollection.add()
- HTMLOptionsCollection.length
- HTMLOptionsCollection.selectedIndex
- HTMLOptionsCollection
- Element.remove
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
