I was trying to remove some items from an array ,
Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); }; var BOM = [0,1,0,1,0,1,1]; var IDLEN = BOM.length; for(var i = 0; i < IDLEN ;++i) { if( BOM[i] == 1) { BOM.remove(i); //IDLEN--; } }
RESULT IS
BOM = [0,0,0,1];
expected result is
BOM = [0,0,0];
its looks like i am doing something wrong , Please help me.
Thanks.
IDLEN
defined? Also, yourremove
method seems familiar toArray.splice
, have you consider using it to accomplish what you want?