/ Published in: JavaScript
remove(array) --> array
Array.remove(a) simply removes all the items in the passed in array from the current scope array. Good for bulk operations.
Expand |
Embed | Plain Text
/** * Remove all passed in items from the current array. If they * dont exist they are ignored. */ Array.prototype.remove = function(a){ // Array Remove - By John Resig (MIT Licensed) var r = function(from, to) { if(from != -1){ var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); } }; for(var i=0; i<a.length;i++){ r.call(this, this.indexOf(a[i])) } return this; } /** non prototype extending method ---------------------------- */ Array.remove = function(t, a){ // Array Remove - By John Resig (MIT Licensed) var r = function(from, to) { if(from != -1){ var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); } }; for(var i=0; i<a.length;i++){ r.call(t, t.indexOf(a[i])) } return t; }
You need to login to post a comment.
