hi,
well, i have two arrays and want to remove in one of them, all elements which exist in the other as well.
- is there a native JS possibility?
- is there a jQuery functino?
- what is best practice to do so (the faster the better)
thanks
p.s.: just post code in other languages too, maybe i can port it to javascript
Update, after accepting answere to help the JS dudes ;-)
// Array Remove - By John Resig (MIT Licensed)
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);
};
// Array Contains - By Helmuth Lammer (TU Vienna)
Array.prototype.contains = function(key){
for(var i = 0; i<this.length; i++){
if(this[i] == key) return i;
}
return false;
}
(There is a native JS method named contains too, but it should work)