remove item from array javascript
Posted
by
Red
on Stack Overflow
See other posts from Stack Overflow
or by Red
Published on 2012-11-06T04:59:01Z
Indexed on
2012/11/06
4:59 UTC
Read the original article
Hit count: 106
JavaScript
|arrays
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 bomlength = 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.
© Stack Overflow or respective owner