The remove() method of the HTMLOptionsCollection interface removes the <option> element specified by the index from this collection.
remove(index)
indexA zero-based integer for the index of the HTMLOptionElement in the HTMLOptionsCollection. If the index is not found the method has no effect.
None (undefined).
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
| Specification |
|---|
| HTML> # dom-htmloptionscollection-remove-dev> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
remove |
1 | 12 | 4 | ≤12.1 | 3.1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
HTMLOptionsCollection.add()HTMLOptionsCollection.lengthHTMLOptionsCollection.selectedIndexHTMLOptionsCollectionElement.remove
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection/remove