Removing options from Select

Removing options from Select tag in Vanilla JavaScript with “for .. of” loop

by Kishankumar S

HTML

<select id="remove-option">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
</select>

JavaScript

var selectOptions = document.querySelectorAll('#remove-option>option');
selectOptions.forEach(function(selectOption) {
  selectOption.remove();
  selectOption = null;
});