Nov
14
Posted on 14-11-2005
Filed Under (Wordpress) by Johan Känngård

Can be found here. Make sure you get the latest version at the bottom of the page (version 0.2). Google Analytics is an advanced hit counter.

(0) Comments    Read More   
Nov
14
Posted on 14-11-2005
Filed Under (JavaScript) by Johan Känngård

If you know the index of the element to remove, you could use the splice method, like this:

var a=['one','two','three','four'];
a.splice(1,1); // Removes 1 element from index 1
alert(a); // Results in 'one','three','four'


If you don’t know the index, but the value of the element, you could add a little method to the Array class like this:

Array.prototype.remove=function(s){
for(i=0;i if(s==this[i]) this.splice(i, 1);
}
}
var a=['one','two','three','four'];
a.remove('three');
alert(a); // Results in 'one','two','four'

(19) Comments    Read More