HTMLOptionsCollection: remove() method
Baseline Widely availableThis feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
>The remove() method of the HTMLOptionsCollection interface removes the <option> element specified by the index from this collection.
Syntax
jsremove(index)
Parameters
index-
A zero-based integer for the index of the
HTMLOptionElementin theHTMLOptionsCollection. If the index is not found the method has no effect.
Return value
None (undefined).
Examples
jsconst 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
| Specification |
|---|
| HTML > # dom-htmloptionscollection-remove-dev > |
Browser compatibility
See also
HTMLOptionsCollection.add()HTMLOptionsCollection.lengthHTMLOptionsCollection.selectedIndexHTMLOptionsCollectionElement.remove
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Oct 2, 2024 by MDN contributors.
View this page on GitHub • Report a problem with this content