Question: I'm having a select box which contains 17 values/options. 

```
<select id="_class" name="_class">
    <option value="0"></option>
    <option value="1">PREKG</option>
    <option value="2">LKG</option>
    <option value="3">UKG</option>
    <option value="4">I</option>
    <option value="5">II</option>
    <option value="6">III</option>
    <option value="7">IV</option>
    <option value="8">V</option>
    <option value="9">VI</option>
    <option value="10">VII</option>
    <option value="11">VIII</option>
    <option value="12">IX</option>
    <option value="13">X</option>
    <option value="14">XI</option>
    <option value="15">XII</option>
    <option value="16">XIII</option>                              
</select>

```

Now, I'm trying to remove the option from 5 to 8. For that, I'm using the following JavaScript code.

```
<script type="text/javascript">
 var _class = document.getElementById("_class");
 for(var i=1; i < _class.length;i++) {
   if(i>=5 && i<=8) {
     _class.remove(i);
   }
 }
</script>

```

But, I'm not getting the expected result, because every time as if the for loop runs, the order of the option is getting changed.

How can I get the desired result?

[Here](http://jsfiddle.net/Gy8j8/) I've attached the Fiddle.

Answer: 
By iterating through the options incrementally, the indices of the options after an option that is removed will be reduced by one as soon as the option is removed (ie: removing the option at index 5 causes options 6 and above to now be indexed as options 5 and above).

To cater for this, reverse the order of the loop to count downwards:

```
var _class = document.getElementById("_class");

for(var i=Math.min(_class.options.length, 8); i >= 5; i--) {
  _class.remove(i);
}

```

<http://jsfiddle.net/Gy8j8/2/>
Hi I faced the same problem. i am pasting my solution.
in fubbe answer these is some problem if user is trying to send higher index first and lower index subsequently ..thereby i am aorting the arguments passed to ensure that indexes (received through parameters) are sorted in ascending order first then our loop will be in reverse order to delete the indexes.

```
HTMLSelectElement.prototype.removeIndexes = removeIndexes;
function removeIndexes(){
  var res = Array.prototype.slice.call(arguments).sort(function(a, b){return     a-b})
  alert(res)
  for (var i=res.length-1;i>=0;i--){
     (function(self,indx){
      self.remove(indx);  
     })(this,res[i])
  }
}
var x = document.getElementById("mySelect");
x.removeIndexes(2,3)

 //------- Another way----------------
 HTMLSelectElement.prototype.removeIndexes = removeIndexes;
 function removeIndexes(){
   var self = this;
   var res = Array.prototype.slice.call(arguments).sort(function(a, b)     {return b-a}).map(function(indx){
   alert(indx)
   self.remove(indx);
 })

 }
 var x = document.getElementById("mySelect");
 x.removeIndexes(2,0,1)

```

Hope this helps

Kind Regards
Gaurav Khurana